diff options
| -rw-r--r-- | config/tsconfig.json | 3 | ||||
| -rw-r--r-- | config/webpack.config.js | 36 | ||||
| -rw-r--r-- | config/webpack/plugins/create-injected-shared-modules-webpack-plugin.js | 38 | ||||
| -rw-r--r-- | config/webpack/plugins/create-manifest-webpack-plugin/index.js | 25 | ||||
| -rw-r--r-- | config/webpack/plugins/create-rules-webpack-plugin.js | 3 | ||||
| -rw-r--r-- | config/webpack/plugins/inject-script-webpack-plugin.js | 3 | ||||
| -rw-r--r-- | src/scripts/functionality/view-khatian/download-information-pdf-page-content.ts (renamed from src/scripts/functionality/view-khatian/download-document-content.ts) | 24 | ||||
| -rw-r--r-- | src/scripts/functionality/view-khatian/index.ts | 4 | ||||
| -rw-r--r-- | src/types/html2pdf.js.d.ts | 1 |
9 files changed, 101 insertions, 36 deletions
diff --git a/config/tsconfig.json b/config/tsconfig.json index 8615fcb..120bfcb 100644 --- a/config/tsconfig.json +++ b/config/tsconfig.json @@ -1,7 +1,4 @@ { - "files": [ - "../src/types/html2pdf.js.d.ts" - ], "compilerOptions": { "outDir": "dist", "sourceMap": true, diff --git a/config/webpack.config.js b/config/webpack.config.js index 78f4060..31bbb8d 100644 --- a/config/webpack.config.js +++ b/config/webpack.config.js @@ -14,13 +14,13 @@ global.webpackRequire = modulePath => require(path.resolve(CONFIG_DIR, "webpack" const CreateManifestPlugin = webpackRequire("plugins/create-manifest-webpack-plugin"); const CreateRulesPlugin = webpackRequire("plugins/create-rules-webpack-plugin"); const InjectScriptPlugin = webpackRequire("plugins/inject-script-webpack-plugin"); +const CreateInjectedSharedModulesPlugin = webpackRequire("plugins/create-injected-shared-modules-webpack-plugin"); const { inlineJavascript } = webpackRequire("utils/inline-javascript"); const { getScriptRuntimeFromType } = webpackRequire("utils/script-runtime"); const { getFileNameHash } = webpackRequire("utils/filename-hash"); const scripts = webpackRequire("utils/scripts"); - const sharedModules = webpackRequire("utils/shared-modules"); const sharedModulesImportedCount = {}; @@ -29,6 +29,12 @@ for (const sharedModule of sharedModules) { sharedModulesImportedCount[sharedModule] = 0; } +const injectedSharedModulesImportedCount = {}; + +for (const sharedModule of sharedModules) { + injectedSharedModulesImportedCount[sharedModule] = 0; +} + const uninjectedScriptEntries = {}; const injectedAfterScriptEntries = {}; const injectedBeforeScriptEntries = {}; @@ -125,6 +131,23 @@ const sharedModuleOptions = { } }; +const injectedModulesOptions = { + externals: sharedModuleExternals, + externalsType: "var", + module: { + rules: [ + { + test: /banglar-bhumi-utils\/src\/.*.(^.?|\.[^d]|[^.]d|[^.][^d])\.(t|j)s$/, + loader: path.resolve(CONFIG_DIR, "webpack/loader/count-imports-loader.js"), + options: { + sharedModulesImportedCount: injectedSharedModulesImportedCount + }, + enforce: "post" + } + ] + } +}; + const uninjectedScriptConfiguration = merge( commonOptions, sharedModuleOptions, @@ -135,6 +158,7 @@ const uninjectedScriptConfiguration = merge( const injectedAfterScriptConfiguration = merge( commonOptions, + injectedModulesOptions, { entry: injectedAfterScriptEntries, plugins: [ @@ -145,6 +169,7 @@ const injectedAfterScriptConfiguration = merge( const injectedBeforeScriptConfiguration = merge( commonOptions, + injectedModulesOptions, { entry: injectedBeforeScriptEntries, plugins: [ @@ -167,11 +192,16 @@ const sharedModulesConfiguration = merge( to: "./" }] }), + new CreateInjectedSharedModulesPlugin({ + injectedSharedModulesImportedCount, + sortedSharedModules + }), + new CreateRulesPlugin(), new CreateManifestPlugin({ sharedModulesImportedCount, + injectedSharedModulesImportedCount, sortedSharedModules - }), - new CreateRulesPlugin() + }) ], module: { rules: [ diff --git a/config/webpack/plugins/create-injected-shared-modules-webpack-plugin.js b/config/webpack/plugins/create-injected-shared-modules-webpack-plugin.js new file mode 100644 index 0000000..88959c5 --- /dev/null +++ b/config/webpack/plugins/create-injected-shared-modules-webpack-plugin.js @@ -0,0 +1,38 @@ +const path = require("path"); +const fs = require("fs"); +const { sources } = require("webpack"); + +const { getFileNameHash } = webpackRequire("utils/filename-hash"); + +class CreateInjectedSharedModulesPlugin { + constructor({ injectedSharedModulesImportedCount, sortedSharedModules }) { + this.injectedSharedModulesImportedCount = injectedSharedModulesImportedCount; + this.sortedSharedModules = sortedSharedModules; + } + + apply(compiler) { + compiler.hooks.compilation.tap("CreateInjectedSharedModulesPlugin", compilation => { + compilation.hooks.processAssets.tap( + { + name: "CreateInjectedSharedModulesPlugin", + stage: compiler.webpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONAL + }, + assets => { + const injectedSharedScripts = this.sortedSharedModules + .filter(sharedModule => this.injectedSharedModulesImportedCount[sharedModule] > 0) + .map(sharedModule => `"/shared/${getFileNameHash(sharedModule, "shared")}.js"`); + + if (injectedSharedScripts.length > 0) { + const injectionCode = `(async()=>{let e=(await Promise.all([${injectedSharedScripts.join(", ")}].map(async e=>(await fetch(chrome.runtime.getURL(e))).text()))).join(""),t=new MutationObserver(()=>{let n=document.querySelector("head > script:nth-child(54)");n&&(n.innerHTML=e+n.innerHTML,t.disconnect())});t.observe(document,{childList:!0,subtree:!0})})();`; + compilation.emitAsset( + `shared/${getFileNameHash("injected-shared-modules", "shared")}.js`, + new sources.RawSource(injectionCode) + ); + } + } + ); + }); + } +} + +module.exports = CreateInjectedSharedModulesPlugin; diff --git a/config/webpack/plugins/create-manifest-webpack-plugin/index.js b/config/webpack/plugins/create-manifest-webpack-plugin/index.js index 2187a05..91ddf3e 100644 --- a/config/webpack/plugins/create-manifest-webpack-plugin/index.js +++ b/config/webpack/plugins/create-manifest-webpack-plugin/index.js @@ -7,8 +7,9 @@ const scripts = webpackRequire("utils/scripts"); const manifest = webpackRequire("plugins/create-manifest-webpack-plugin/manifest-template.json"); class CreateManifestPlugin { - constructor({ sharedModulesImportedCount, sortedSharedModules }) { + constructor({ sharedModulesImportedCount, injectedSharedModulesImportedCount, sortedSharedModules }) { this.sharedModulesImportedCount = sharedModulesImportedCount; + this.injectedSharedModulesImportedCount = injectedSharedModulesImportedCount; this.sortedSharedModules = sortedSharedModules; } @@ -17,8 +18,7 @@ class CreateManifestPlugin { compilation.hooks.processAssets.tap( { name: "CreateManifestPlugin", - stage: compiler.webpack.Compilation.PROCESS_ASSETS_STAGE_ANALYSE, - additionalAssets: true + stage: compiler.webpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONAL }, assets => { manifest.version = require(path.resolve(ROOT_DIR, "package.json")).version; @@ -33,12 +33,12 @@ class CreateManifestPlugin { const scriptRuntime = getScriptRuntimeFromType(scriptType); if (typeof arrangedScripts[scriptPath][scriptRuntime] === "undefined") { - arrangedScripts[scriptPath][scriptRuntime] = []; - } + arrangedScripts[scriptPath][scriptRuntime] = []; + } - arrangedScripts[scriptPath][scriptRuntime].push(`scripts/${getFileNameHash(scriptType, scriptPath)}.js`); + arrangedScripts[scriptPath][scriptRuntime].push(`scripts/${getFileNameHash(scriptType, scriptPath)}.js`); + } } - } manifest.content_scripts.push({ matches: [`*://banglarbhumi.gov.in/BanglarBhumi/*`], @@ -66,7 +66,7 @@ class CreateManifestPlugin { } } - const resources = []; + let resources = []; for (const assetName in assets) { if (/^assets\/.*\.(jpg|png|gif)$/.test(assetName)) { @@ -74,6 +74,15 @@ class CreateManifestPlugin { } } + const injectedSharedModules = this.sortedSharedModules + .filter(sharedModule => this.injectedSharedModulesImportedCount[sharedModule] > 0) + .map(sharedModule => `shared/${getFileNameHash(sharedModule, "shared")}.js`); + + if (injectedSharedModules.length > 0) { + resources = resources.concat(injectedSharedModules); + manifest.content_scripts[0].js.unshift(`shared/${getFileNameHash("injected-shared-modules", "shared")}.js`); + } + if (resources.length > 0) { manifest.web_accessible_resources = [ { diff --git a/config/webpack/plugins/create-rules-webpack-plugin.js b/config/webpack/plugins/create-rules-webpack-plugin.js index 4a02e2f..d02decd 100644 --- a/config/webpack/plugins/create-rules-webpack-plugin.js +++ b/config/webpack/plugins/create-rules-webpack-plugin.js @@ -8,8 +8,7 @@ class CreateRulesPlugin { compilation.hooks.processAssets.tap( { name: "CreateRulesPlugin", - stage: compiler.webpack.Compilation.PROCESS_ASSETS_ADDITIONAL, - additionalAssets: true + stage: compiler.webpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONAL }, assets => { const ruleFileNames = fs.readdirSync(path.resolve(SOURCE_DIR, "rules")); diff --git a/config/webpack/plugins/inject-script-webpack-plugin.js b/config/webpack/plugins/inject-script-webpack-plugin.js index c597e9a..0c42dfd 100644 --- a/config/webpack/plugins/inject-script-webpack-plugin.js +++ b/config/webpack/plugins/inject-script-webpack-plugin.js @@ -12,8 +12,7 @@ class InjectScriptPlugin { compilation.hooks.processAssets.tapPromise( { name: "InjectScriptPlugin", - stage: compiler.webpack.Compilation.PROCESS_ASSETS_STAGE_ANALYSE, - additionalAssets: true + stage: compiler.webpack.Compilation.PROCESS_ASSETS_STAGE_ANALYSE }, async assets => { for (const assetName in assets) { diff --git a/src/scripts/functionality/view-khatian/download-document-content.ts b/src/scripts/functionality/view-khatian/download-information-pdf-page-content.ts index 249e2b1..9ff18ec 100644 --- a/src/scripts/functionality/view-khatian/download-document-content.ts +++ b/src/scripts/functionality/view-khatian/download-information-pdf-page-content.ts @@ -75,8 +75,12 @@ export default (isPlotInformation: boolean, details: string, { district, block, border-right: 0 !important; } - .details#plot-information > div:nth-child(2) { - display: none; + .details#plot-information > div:nth-child(2), + .details#plot-information > div:nth-child(1) > div:nth-child(3) > table > tbody > tr > td:nth-child(4), + .details#plot-information > div:nth-child(1) > div:nth-child(3) > table > tbody > tr > th:nth-child(4), + .details#khatian-information > table > tbody > tr > td:nth-child(1) > p:nth-child(3), + .details#khatian-information > table > tbody > tr > td:nth-child(2) { + display: none !important; } .details#plot-information > div:nth-child(1) > div:nth-child(5) > table > tbody > tr { @@ -88,10 +92,6 @@ export default (isPlotInformation: boolean, details: string, { district, block, width: 100% !important; } - .details#khatian-information > table > tbody > tr > td:nth-child(2) { - display: none; - } - .details#khatian-information > table > tbody > tr > td:nth-child(1) > div:nth-child(1), .details#khatian-information > table > tbody > tr > td:nth-child(1) > p:nth-child(4) { text-align: center; @@ -154,10 +154,9 @@ export default (isPlotInformation: boolean, details: string, { district, block, border-color: black !important; } - .details#khatian-information > table > tbody > tr > td:nth-child(1) > div:nth-child(5) > table > tbody > tr:last-child { - border: none !important; - } - + .details#khatian-information > table > tbody > tr > td:nth-child(1) > div:nth-child(5) > table > tbody > tr:last-child, + .details#plot-information > div:nth-child(1) > div:nth-child(3) > table > tbody > tr > td:nth-child(3), + .details#plot-information > div:nth-child(1) > div:nth-child(3) > table > tbody > tr > th:nth-child(3), .details#khatian-information > table tbody tr tr th:last-child, .details table tbody tr tr td:last-child, #locater-information tr > td:last-child { border-right: none !important; @@ -176,10 +175,6 @@ export default (isPlotInformation: boolean, details: string, { district, block, width: 100% !important; } - .details#khatian-information > table > tbody > tr > td:nth-child(1) > p:nth-child(3) { - display: none; - } - .details#khatian-information > table > tbody > tr > td:nth-child(1) > div:nth-child(2) > table > tbody > tr:nth-child(1) > th { width: 50%; } @@ -211,7 +206,6 @@ export default (isPlotInformation: boolean, details: string, { district, block, tableBodyElement = document.createElement("tbody"); tableElement.appendChild(tableBodyElement); const detailsElement = document.querySelector("#plot-information > div:nth-child(1)"); - console.log(detailsElement.querySelector("div:nth-child(2)")); detailsElement.insertBefore(tableElement, detailsElement.querySelector("div:nth-child(2)")); ` : ` diff --git a/src/scripts/functionality/view-khatian/index.ts b/src/scripts/functionality/view-khatian/index.ts index 0cb3947..e29e8a4 100644 --- a/src/scripts/functionality/view-khatian/index.ts +++ b/src/scripts/functionality/view-khatian/index.ts @@ -1,5 +1,5 @@ import { downloadPDF } from "@/shared/download-pdf"; -import getDetailsPDFContent from "@/scripts/functionality/view-khatian/download-document-content"; +import getDownloadInformationPDFPageContent from "@/scripts/functionality/view-khatian/download-information-pdf-page-content"; declare function load(): void; @@ -27,7 +27,7 @@ document.addEventListener("DOMContentLoaded", () => { const downloadInformationPDF = () => { let contentElement = document.getElementById(isPlotInformation ? "plotdetails" : "khdetails"); - const documentStringContent = getDetailsPDFContent(!!isPlotInformation, contentElement!.innerHTML, { + const documentStringContent = getDownloadInformationPDFPageContent(!!isPlotInformation, contentElement!.innerHTML, { district: getValueOfSelectElement("#lstDistrictCode1"), block: getValueOfSelectElement("#lstBlockCode1"), mouza: getValueOfSelectElement("#lstMouzaList") diff --git a/src/types/html2pdf.js.d.ts b/src/types/html2pdf.js.d.ts deleted file mode 100644 index c9a972e..0000000 --- a/src/types/html2pdf.js.d.ts +++ /dev/null @@ -1 +0,0 @@ -declare module "html2pdf.js"; |
