diff --git a/package-lock.json b/package-lock.json index a72aa01..5f51deb 100644 --- a/package-lock.json +++ b/package-lock.json @@ -96,6 +96,14 @@ "integrity": "sha512-IG8AE1m2pWtPqQ7wXhFhy6Q59bwwnLwO36v5Rit2FrbXCIp8Sk8E2PfUCreyrdo17STwFSKDAkitVuVYbpEHvQ==", "dev": true }, + "@types/jquery": { + "version": "3.5.4", + "resolved": "https://registry.npmjs.org/@types/jquery/-/jquery-3.5.4.tgz", + "integrity": "sha512-//9CHhaUt/rurMJTxGI+I6DmsNHgYU6d8aSLFfO5dB7+10lwLnaWT0z5GY/yY82Q/M+B+0Qh3TixlJ8vmBeqIw==", + "requires": { + "@types/sizzle": "*" + } + }, "@types/json-schema": { "version": "7.0.6", "resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.6.tgz", @@ -108,6 +116,11 @@ "integrity": "sha512-6QlRuqsQ/Ox/aJEQWBEJG7A9+u7oSYl3mem/K8IzxXG/kAGbV1YPD9Bg9Zw3vyxC/YP+zONKwy8hGkSt1jxFMw==", "dev": true }, + "@types/sizzle": { + "version": "2.3.2", + "resolved": "https://registry.npmjs.org/@types/sizzle/-/sizzle-2.3.2.tgz", + "integrity": "sha512-7EJYyKTL7tFR8+gDbB6Wwz/arpGa0Mywk1TJbNzKzHtzbwVmY4HR9WqS5VV7dsBUKQmPNr192jHr/VpBluj/hg==" + }, "@webassemblyjs/ast": { "version": "1.9.0", "resolved": "https://registry.npmjs.org/@webassemblyjs/ast/-/ast-1.9.0.tgz", @@ -1014,6 +1027,11 @@ "supports-color": "^7.0.0" } }, + "jquery": { + "version": "3.5.1", + "resolved": "https://registry.npmjs.org/jquery/-/jquery-3.5.1.tgz", + "integrity": "sha512-XwIBPqcMn57FxfT+Go5pzySnm4KWkT1Tv7gjrpT1srtf8Weynl6R273VJ5GjkRb51IzMp5nbaPjJXMWeju2MKg==" + }, "json-parse-better-errors": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/json-parse-better-errors/-/json-parse-better-errors-1.0.2.tgz", diff --git a/package.json b/package.json index 621d738..1847c3c 100644 --- a/package.json +++ b/package.json @@ -24,5 +24,9 @@ "typescript": "^4.0.5", "webpack": "^5.3.2", "webpack-cli": "^4.1.0" + }, + "dependencies": { + "@types/jquery": "^3.5.4", + "jquery": "^3.5.1" } } diff --git a/public/manifest.json b/public/manifest.json index e2c9288..f5200d0 100644 --- a/public/manifest.json +++ b/public/manifest.json @@ -2,10 +2,17 @@ "manifest_version": 2, "name": "FreshSearchResult", "description": "新鮮な情報の見分けをつけます", - "version": "0.0.1", + "version": "1.0.0", "icons": { "128": "image/icon128.png" }, - "background": { - "scripts": ["js/main.js"] - }, - "permissions": ["contextMenus", "tabs"] + "content_scripts": [ + { + "matches": [ + "https://www.google.com/*", + "http://www.google.com/*" + ], + "js": [ + "js/main.js" + ] + } + ] } \ No newline at end of file diff --git a/src/main.ts b/src/main.ts index e7b5153..65e3433 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,17 +1,21 @@ -const openTab = (query?: string) => { - if (query) { - chrome.tabs.create({ url: `https://www.google.com/search?q=${query}` }); - } -} +import $ from 'jquery'; -chrome.runtime.onInstalled.addListener((): void => { - chrome.contextMenus.create({ - id: "sample", - title: "選択した文字列を検索する", - contexts: ["selection"] - }); -}); +const NOW = new Date(); +const OLDEST = new Date(NOW.getFullYear() - 10, NOW.getMonth(), NOW.getDate(), NOW.getHours(), NOW.getMinutes(), NOW.getSeconds(), NOW.getMilliseconds()); +const BASE = NOW.getTime() - OLDEST.getTime(); +const ONEMINUSCOLOR = [255-205, 255-170, 255-85]; -chrome.contextMenus.onClicked.addListener((info, tab): void => { - openTab(info.selectionText); +$(function() { + // $("body").css("background-color", "#CCC6B8"); + $(".g").each(function(index: number, element: HTMLElement) { + const span = $(element).find("span.f"); + if (span.length > 0) { + const date = new Date(span[0].innerHTML.substring(0, 10)); + const elapsed = NOW.getTime() - date.getTime(); + const density = 1 - Math.max(Math.min(elapsed / BASE, 1), 0); + element.style.backgroundColor = `rgba(${205+ONEMINUSCOLOR[0]*density}, ${170+ONEMINUSCOLOR[1]*density}, ${85+ONEMINUSCOLOR[2]*density}, 0.5)`; + } else { + element.style.backgroundColor = `rgba(51, 221, 255, 0.2)`; + } + }); }); \ No newline at end of file