Skip to content

Commit

Permalink
add result color change
Browse files Browse the repository at this point in the history
  • Loading branch information
futahei committed Nov 3, 2020
1 parent 58d7eb8 commit 3d85a11
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 19 deletions.
18 changes: 18 additions & 0 deletions package-lock.json

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

4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
17 changes: 12 additions & 5 deletions public/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
}
]
}
32 changes: 18 additions & 14 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -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)`;
}
});
});

0 comments on commit 3d85a11

Please sign in to comment.