diff --git a/public/manifest.json b/public/manifest.json index 986e806..65f9dbf 100644 --- a/public/manifest.json +++ b/public/manifest.json @@ -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": [ diff --git a/src/main.ts b/src/main.ts index 1c09096..82e321a 100644 --- a/src/main.ts +++ b/src/main.ts @@ -3,7 +3,8 @@ import $ from 'jquery'; let range: JQuery; 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()); @@ -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(/(?\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(); @@ -34,18 +32,22 @@ const main = function() { } element.style.backgroundColor = `rgba(51, 221, 255, 0.2)`; }); + + chrome.storage.sync.set({"fsr-year": rangeVal}); } $(function() { $("基準年数:0").appendTo("#result-stats"); - range = $("").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 = $("").attr({ + type: "range", + id: "elapsedBaseYear", + min: "1", + max: "10", + value: res["fsr-year"] + }).appendTo("#result-stats"); + range.on("input", main); - main(); + main(); + }); }); \ No newline at end of file