Skip to content

Commit

Permalink
save base year value to chrome
Browse files Browse the repository at this point in the history
  • Loading branch information
futahei committed Dec 7, 2020
1 parent d20c384 commit 0691648
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 17 deletions.
2 changes: 1 addition & 1 deletion public/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"manifest_version": 2,
"name": "FreshSearchResult",
"description": "新鮮な情報の見分けをつけます",
"version": "2.0.1",
"version": "2.1.0",
"icons": { "128": "image/icon128.png" },
"permissions": ["storage"],
"content_scripts": [
Expand Down
34 changes: 18 additions & 16 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import $ from 'jquery';
let range: JQuery<HTMLElement>;

const main = function() {
const baseYear = Number(range.val());
const rangeVal = range.val();
const baseYear = Number(rangeVal);
$("#baseYear").text(baseYear);
const NOW = new Date();
const OLDEST = new Date(NOW.getFullYear() - Number(range.val()), NOW.getMonth(), NOW.getDate(), NOW.getHours(), NOW.getMinutes(), NOW.getSeconds(), NOW.getMilliseconds());
Expand All @@ -13,19 +14,16 @@ const main = function() {
const span = $(element).find("span.f");
if (span.length > 0) {
let date: Date|null = null;
if (span[0].innerHTML.substring(0, 10).match(/\d{4}\/\d{2}\/\d{2}/))
{
if (span[0].innerHTML.substring(0, 10).match(/\d{4}\/\d{2}\/\d{2}/)) {
date = new Date(span[0].innerHTML.substring(0, 10));
} else if (span[0].innerHTML.substring(0, 4).match(/\d* /))
{
} else if (span[0].innerHTML.substring(0, 4).match(/\d* /)) {
const found = span[0].innerHTML.substring(0, 4).match(/(?<days>\d*) /);
const days = Number(found?.groups?.days || "0");
date = new Date(NOW.getTime());
date.setDate(NOW.getDate() - days);
}

if (date)
{
if (date) {
const elapsed = NOW.getTime() - date.getTime();
const density = 1 - Math.max(Math.min(elapsed / BASE, 1), 0);
element.style.opacity = (Math.max(density, 0.1)).toString();
Expand All @@ -34,18 +32,22 @@ const main = function() {
}
element.style.backgroundColor = `rgba(51, 221, 255, 0.2)`;
});

chrome.storage.sync.set({"fsr-year": rangeVal});
}

$(function() {
$("<span>基準年数:<span id='baseYear'>0</span>年</span>").appendTo("#result-stats");
range = $("<input>").attr({
type: "range",
id: "elapsedBaseYear",
min: "1",
max: "10",
value: "5"
}).appendTo("#result-stats");
range.on("input", main);
const v = chrome.storage.sync.get({"fsr-year": "5"}, function(res) {
range = $("<input>").attr({
type: "range",
id: "elapsedBaseYear",
min: "1",
max: "10",
value: res["fsr-year"]
}).appendTo("#result-stats");
range.on("input", main);

main();
main();
});
});

0 comments on commit 0691648

Please sign in to comment.