Skip to content

Commit

Permalink
bump manifest_version to 3 (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
ytakahashi committed Aug 5, 2023
1 parent 489b522 commit 9f5b21d
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 21 deletions.
32 changes: 32 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"webextension-polyfill": "^0.10.0"
},
"devDependencies": {
"@types/chrome": "^0.0.243",
"@types/copy-webpack-plugin": "^10.1.0",
"@types/html-webpack-plugin": "^3.2.6",
"@types/webextension-polyfill": "^0.10.1",
Expand Down
13 changes: 8 additions & 5 deletions public/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@
"name": "Google date range search",
"version": "1.0.0",
"description": "Google date range search extension.",
"manifest_version": 2,
"manifest_version": 3,
"icons": {
"16": "images/icon16.png",
"48": "images/icon48.png",
"128": "images/icon128.png"
},
"permissions": ["tabs"],
"page_action": {
"permissions": [
"declarativeContent",
"tabs"
],
"action": {
"default_popup": "popup.html",
"default_icon": {
"16": "images/icon16.png",
Expand All @@ -18,8 +21,8 @@
}
},
"background": {
"scripts": ["script.js"],
"persistent": false
"service_worker": "script.js",
"type": "module"
},
"author": "ytakahashi",
"homepage_url": "https://github.com/ytakahashi/google-date-range-search"
Expand Down
32 changes: 17 additions & 15 deletions src/script.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
import browser from 'webextension-polyfill'

// https://stackoverflow.com/a/58694071
const googleUrl: RegExp =
/http(s)?:\/\/(www\.)?google\.(com|ad|ae|com.af|com.ag|com.ai|al|am|co.ao|com.ar|as|at|com.au|az|ba|com.bd|be|bf|bg|com.bh|bi|bj|com.bn|com.bo|com.br|bs|bt|co.bw|by|com.bz|ca|cd|cf|cg|ch|ci|co.ck|cl|cm|cn|com.co|co.cr|com.cu|cv|com.cy|cz|de|dj|dk|dm|com.do|dz|com.ec|ee|com.eg|es|com.et|fi|com.fj|fm|fr|ga|ge|gg|com.gh|com.gi|gl|gm|gp|gr|com.gt|gy|com.hk|hn|hr|ht|hu|co.id|ie|co.il|im|co.in|iq|is|it|je|com.jm|jo|co.jp|co.ke|com.kh|ki|kg|co.kr|com.kw|kz|la|com.lb|li|lk|co.ls|lt|lu|lv|com.ly|co.ma|md|me|mg|mk|ml|com.mm|mn|ms|com.mt|mu|mv|mw|com.mx|com.my|co.mz|com.na|com.nf|com.ng|com.ni|ne|nl|no|com.np|nr|nu|co.nz|com.om|com.pa|com.pe|com.pg|com.ph|com.pk|pl|pn|com.pr|ps|pt|com.py|com.qa|ro|ru|rw|com.sa|com.sb|sc|se|com.sg|sh|si|sk|com.sl|sn|so|sm|sr|st|com.sv|td|tg|co.th|com.tj|tk|tl|tm|tn|to|com.tr|tt|com.tw|co.tz|com.ua|co.ug|co.uk|com.uy|co.uz|com.vc|co.ve|vg|co.vi|com.vn|vu|ws|rs|co.za|co.zm|co.zw|cat)\/.*/

const isGoogleUrl = (url: string | undefined): boolean => {
if (url == undefined) {
return false
}
const googleUrlPattern: string =
'http(s)?://(www.)?google.(com|ad|ae|com.af|com.ag|com.ai|al|am|co.ao|com.ar|as|at|com.au|az|ba|com.bd|be|bf|bg|com.bh|bi|bj|com.bn|com.bo|com.br|bs|bt|co.bw|by|com.bz|ca|cd|cf|cg|ch|ci|co.ck|cl|cm|cn|com.co|co.cr|com.cu|cv|com.cy|cz|de|dj|dk|dm|com.do|dz|com.ec|ee|com.eg|es|com.et|fi|com.fj|fm|fr|ga|ge|gg|com.gh|com.gi|gl|gm|gp|gr|com.gt|gy|com.hk|hn|hr|ht|hu|co.id|ie|co.il|im|co.in|iq|is|it|je|com.jm|jo|co.jp|co.ke|com.kh|ki|kg|co.kr|com.kw|kz|la|com.lb|li|lk|co.ls|lt|lu|lv|com.ly|co.ma|md|me|mg|mk|ml|com.mm|mn|ms|com.mt|mu|mv|mw|com.mx|com.my|co.mz|com.na|com.nf|com.ng|com.ni|ne|nl|no|com.np|nr|nu|co.nz|com.om|com.pa|com.pe|com.pg|com.ph|com.pk|pl|pn|com.pr|ps|pt|com.py|com.qa|ro|ru|rw|com.sa|com.sb|sc|se|com.sg|sh|si|sk|com.sl|sn|so|sm|sr|st|com.sv|td|tg|co.th|com.tj|tk|tl|tm|tn|to|com.tr|tt|com.tw|co.tz|com.ua|co.ug|co.uk|com.uy|co.uz|com.vc|co.ve|vg|co.vi|com.vn|vu|ws|rs|co.za|co.zm|co.zw|cat)/.*'

return googleUrl.test(url)
}
// https://developer.chrome.com/docs/extensions/reference/action/#emulating-pageactions-with-declarativecontent
chrome.runtime.onInstalled.addListener(() => {
chrome.action.disable()
chrome.declarativeContent.onPageChanged.removeRules(undefined, () => {
const rule = {
conditions: [
new chrome.declarativeContent.PageStateMatcher({
pageUrl: { urlMatches: googleUrlPattern },
}),
],
actions: [new chrome.declarativeContent.ShowAction()],
}

browser.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
if (isGoogleUrl(tab.url)) {
browser.pageAction.show(tabId)
}
const rules = [rule]
chrome.declarativeContent.onPageChanged.addRules(rules)
})
})
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
// "typeRoots": [], /* List of folders to include type definitions from. */
// "types": [], /* Type declaration files to be included in compilation. */
"types": ["chrome"], /* Type declaration files to be included in compilation. */
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
Expand Down

0 comments on commit 9f5b21d

Please sign in to comment.