From 12cddae9af310a8214b84ff30c636fb17d82a2d3 Mon Sep 17 00:00:00 2001 From: Waldemar B Date: Fri, 24 Jul 2020 21:50:35 +0200 Subject: [PATCH] Version 1.9.6 - Added possibility to change 'default values' (interval, mode, etc.) #48 - Added possibility to ignore link addresses #52 - Added possibility to delete HTML comments #51 - Minor changes - Fiexed bugs --- src/_locales/en/messages.json | 34 +++++++++++- src/_locales/fr/messages.json | 38 ++++++++++++- src/_locales/pl/messages.json | 34 +++++++++++- src/bg.js | 8 ++- src/changelog.js | 4 ++ src/manifest.json | 2 +- src/options.html | 64 ++++++++++++++++------ src/options.js | 47 +++++++++++++++- src/shared.js | 100 +++++++++++++++++++++++++++------- src/sidebar.html | 4 ++ src/sidebar.js | 64 +++++++++++++++------- src/view.html | 2 + src/view.js | 74 ++++++++++++++++--------- 13 files changed, 385 insertions(+), 90 deletions(-) diff --git a/src/_locales/en/messages.json b/src/_locales/en/messages.json index 1e7c7f5..2782429 100644 --- a/src/_locales/en/messages.json +++ b/src/_locales/en/messages.json @@ -28,7 +28,7 @@ "message": "Title:" }, "scanFreq": { - "message": "Scan every:" + "message": "Interval:" }, "minutes": { "message": "Minute(s)" @@ -234,7 +234,7 @@ "message": "Skip minor changes" }, "highlightOutsideChanges": { - "message": "Highlight changes outside the scanned element" + "message": "Show changes outside the scanned element" }, "subHighlightOutside": { "message": "Applies to partially scanned pages" @@ -488,6 +488,12 @@ "deleteScripts":{ "message": "Delete scripts" }, + "deleteComments":{ + "message": "Delete comments" + }, + "ignoreHrefs":{ + "message": "Ignore link addresses" + }, "yes":{ "message": "Yes" }, @@ -514,5 +520,29 @@ }, "tooltipStopOpening":{ "message": "\r Stop opening changed pages (middle-click)" + }, + "h3sidebar":{ + "message": "Sidebar" + }, + "h3defaultValues":{ + "message": "Default values" + }, + "defaultInterval":{ + "message": "Default interval" + }, + "defaultMode":{ + "message": "Default mode" + }, + "defaultIgnoreNumbers":{ + "message": "By default, ignore number changes" + }, + "defaultDeleteScripts":{ + "message": "By default, delete scripts" + }, + "defaultDeleteComments":{ + "message": "By default, delete comments" + }, + "defaultIgnoreHrefs":{ + "message": "By default, ignore link addresses" } } diff --git a/src/_locales/fr/messages.json b/src/_locales/fr/messages.json index 9a6cb94..b3da9b2 100644 --- a/src/_locales/fr/messages.json +++ b/src/_locales/fr/messages.json @@ -28,7 +28,7 @@ "message": "Titre :" }, "scanFreq": { - "message": "Tout scanner :" + "message": "Intervalle :" }, "minutes": { "message": "Minute(s)" @@ -233,6 +233,12 @@ "skipMinorChanges": { "message": "Passer les modifications mineures" }, + "highlightOutsideChanges": { + "message": "Afficher les changements en dehors de l'élément scanné" + }, + "subHighlightOutside": { + "message": "Pour les pages partiellement scannées" + }, "changeOf": { "message": "Modification $1 sur $2" }, @@ -482,6 +488,12 @@ "deleteScripts":{ "message": "Supprimer les scripts" }, + "deleteComments":{ + "message": "Supprimer les commentaires" + }, + "ignoreHrefs":{ + "message": "Ignorer les adresses des liens" + }, "yes":{ "message": "Oui" }, @@ -508,5 +520,29 @@ }, "tooltipStopOpening":{ "message": "\r Arrêtez d'ouvrir les pages modifiées (Clic du milieu)" + }, + "h3sidebar":{ + "message": "Panneau latéral" + }, + "h3defaultValues":{ + "message": "Valeurs par défaut" + }, + "defaultInterval":{ + "message": "Intervalle par défaut" + }, + "defaultMode":{ + "message": "Mode par défaut" + }, + "defaultIgnoreNumbers":{ + "message": "Par défaut, ignorer les modifications de nombres" + }, + "defaultDeleteScripts":{ + "message": "Par défaut, supprimer les scripts" + }, + "defaultDeleteComments":{ + "message": "Par défaut, supprimer les commentaires" + }, + "defaultIgnoreHrefs":{ + "message": "Par défaut, ignorer les adresses des liens" } } diff --git a/src/_locales/pl/messages.json b/src/_locales/pl/messages.json index 6b54b9a..f0768f0 100644 --- a/src/_locales/pl/messages.json +++ b/src/_locales/pl/messages.json @@ -28,7 +28,7 @@ "message": "Tytuł:" }, "scanFreq": { - "message": "Skanuj co:" + "message": "Interwał:" }, "minutes": { "message": "Minut/y" @@ -234,7 +234,7 @@ "message": "Pomiń drobne zmiany" }, "highlightOutsideChanges": { - "message": "Podświetl zmiany poza skanowanym elementem" + "message": "Pokaż zmiany poza skanowanym elementem" }, "subHighlightOutside": { "message": "Dotyczy stron skanowanych częściowo" @@ -488,6 +488,12 @@ "deleteScripts":{ "message": "Usuwaj skrypty" }, + "deleteComments":{ + "message": "Usuwaj komentarze" + }, + "ignoreHrefs":{ + "message": "Ignoruj adresy odnośników" + }, "yes":{ "message": "Tak" }, @@ -514,5 +520,29 @@ }, "tooltipStopOpening":{ "message": "\r Zatrzymaj otwieranie zmienionych stron (środkowy przycisk)" + }, + "h3sidebar":{ + "message": "Panel boczny" + }, + "h3defaultValues":{ + "message": "Wartości domyślne" + }, + "defaultInterval":{ + "message": "Domyślny interwał" + }, + "defaultMode":{ + "message": "Domyślny tryb" + }, + "defaultIgnoreNumbers":{ + "message": "Domyślnie ignoruj zmiany liczb" + }, + "defaultDeleteScripts":{ + "message": "Domyślnie usuwaj skrypty" + }, + "defaultDeleteComments":{ + "message": "Domyślnie usuwaj komentarze" + }, + "defaultIgnoreHrefs":{ + "message": "Domyślnie ignoruj adresy odnośników" } } diff --git a/src/bg.js b/src/bg.js index 4beb661..395fd17 100644 --- a/src/bg.js +++ b/src/bg.js @@ -29,6 +29,12 @@ function handleInstalled(details) { "scrollbarMarkers":true, "faviconService":"native", "notificationSound":"notification.opus", + "defaultFreq":8, + "defaultMode":"m0", + "defaultIgnoreNumbers":false, + "defaultDeleteScripts":true, + "defaultDeleteComments":true, + "defaultIgnoreHrefs":false, }; if(details.reason==="install"){ browser.storage.local.get(['sites','settings']).then(result=>{ @@ -122,7 +128,7 @@ let delayCurrentId, browser.runtime.onMessage.addListener(run); function run(m,s){ - if(m.addThis)rqstAdd(m.url,m.title,m.favicon,m.mode,m.freq,m.addBookmark,m.cssSelector,m.ignoreNumbers,m.deleteScript); + if(m.addThis)rqstAdd(m.url,m.title,m.favicon,m.mode,m.freq,m.addBookmark,m.cssSelector,m.ignoreNumbers,m.deleteScript,m.deleteComments,m.ignoreHrefs); if(m.scanSites)scanSites(m.force); if(m.openSites)openSite(); if(m.addToContextMenu!==undefined)showContext(m.addToContextMenu); diff --git a/src/changelog.js b/src/changelog.js index 12af7d6..5ede3b3 100644 --- a/src/changelog.js +++ b/src/changelog.js @@ -9,6 +9,10 @@ function generateChangelog(){ changelogGenerated=true; let changelog=`[ + {"version":"1.9.6", + "changes":["Added possibility to change 'default values' (interval, mode, etc.)","#48","Added possibility to ignore link addresses","#52","Added possibility to delete HTML comments","#51","Moved execution of some functions from sidebar to background","Minor changes","Fiexed bugs"], + "changesPL":["Dodano możliwość zmiany 'wartości domyślnych' (interwał, tryb, itp.)","#48","Dodano możliwość ignorowania adresów odnośników","#52","Dodano możliwość usunięcia komentarzy HTML","#51","Przeniesiono wykonywanie niektórtch funkcji z panelu bocznego do tła","Drobne zmiany","Naprawiono błędy"] + }, {"version":"1.9.5", "changes":["Fixed bug","#36","Added possibility to change options individually for each pages","Added possibility to delete JS scripts","Added links to GitHub in 'Changelog'","Added possibility to change sound of the notification","Added possibility to stop openning next pages (Middle-click the button on a toolbar)","#42","Minor changes","Fixed bugs"], "changesPL":["Naprawiono błąd","#36","Dodano możliwość zmiany opcji indywidualnie dla każdej strony","Dodano możliwość usunięcia skryptów JS","Dodano odnośniki do GitHuba w 'Historii zmian' ","Dodano możliwość zmiany dźwięku powiadomienia","Dodano możliwość zatrzymania otwierania kolejnych stron (Kliknięcie środkowym przyciskiem myszy przycisku na pasku narzędzi)","#42","Drobne zmiany","Naprawiono błędy"] diff --git a/src/manifest.json b/src/manifest.json index 4a37a74..5b2b4e6 100644 --- a/src/manifest.json +++ b/src/manifest.json @@ -2,7 +2,7 @@ "manifest_version": 2, "name": "__MSG_extensionName__", "description": "__MSG_extensionDescription__", - "version": "1.9.5.1", + "version": "1.9.6", "default_locale": "en", "icons": { "48": "icons/icon.svg", diff --git a/src/options.html b/src/options.html index 43a0950..bf5d495 100644 --- a/src/options.html +++ b/src/options.html @@ -33,25 +33,28 @@

- -
-
- +

- +
- +
+

+
- +

@@ -144,6 +142,40 @@

+

+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
diff --git a/src/options.js b/src/options.js index 1dd6531..5da338b 100644 --- a/src/options.js +++ b/src/options.js @@ -88,7 +88,8 @@ function saveOptions(){ const rqstTime=parseInt(document.getElementById("requestTime").value*1000), - period=parseInt(document.getElementById("period").value); + period=parseInt(document.getElementById("period").value), + freq=parseInt(document.getElementById("defaultFreq").value); let settings={ notificationVolume: parseInt(document.getElementById("notificationVolume").value), notificationTime: parseInt(document.getElementById("notificationTime").value), @@ -115,7 +116,13 @@ function saveOptions(){ highlightOutsideChanges: document.getElementById("highlightOutsideChanges").checked, scrollbarMarkers: document.getElementById("scrollbarMarkers").checked, faviconService: document.getElementById("favicon").value, - notificationSound: document.getElementById("notificationSound").value||document.getElementById("externalSound").value + notificationSound: document.getElementById("notificationSound").value||document.getElementById("externalSound").value, + defaultFreq: freq>0?freq*parseFloat(document.getElementById("defaultUnit").value):8, + defaultMode: document.getElementById("defaultMode").value, + defaultIgnoreNumbers: document.getElementById("defaultIgnoreNumbers").checked, + defaultDeleteScripts: document.getElementById("defaultDeleteScripts").checked, + defaultDeleteComments: document.getElementById("defaultDeleteComments").checked, + defaultIgnoreHrefs: document.getElementById("defaultIgnoreHrefs").checked, }; browser.storage.local.set({settings:settings}); if(!settings.popupList)browser.browserAction.setPopup({popup:"/popup.html"}); @@ -171,6 +178,23 @@ function restoreOptions(){ document.getElementById("externalSound").value=s.notificationSound; document.getElementById("rowExternalSound").className="row"; } + const freq=s.defaultFreq||8; + let unit; + if(!(freq%168)) + unit=168; + else if(!(freq%24)) + unit=24; + else if(freq<1) + unit=0.0166667; + else + unit=1; + document.getElementById("defaultFreq").value=parseInt(freq/unit); + document.getElementById("defaultUnit").value=unit; + document.getElementById("defaultMode").value=s.defaultMode; + document.getElementById("defaultIgnoreNumbers").checked=s.defaultIgnoreNumbers; + document.getElementById("defaultDeleteScripts").checked=s.defaultDeleteScripts; + document.getElementById("defaultDeleteComments").checked=s.defaultDeleteComments; + document.getElementById("defaultIgnoreHrefs").checked=s.defaultIgnoreHrefs; }); restoreShortcut(); } @@ -291,6 +315,25 @@ function translate(){ sound[1].text=i18n("sound")+"2"; sound[2].text=i18n("externalSound"); document.getElementById("externalSound").placeholder=i18n("soundUrl"); + document.getElementById("h3sidebar").textContent=i18n("h3sidebar"); + document.getElementById("h3defaultValues").textContent=i18n("h3defaultValues"); + document.getElementById("labelDefaultInterval").textContent=i18n("defaultInterval"); + document.getElementById("labelDefaultMode").textContent=i18n("defaultMode"); + let selectFreq=document.getElementById("defaultUnit").options; + selectFreq[0].text=i18n("minutes"); + selectFreq[1].text=i18n("hours"); + selectFreq[2].text=i18n("days"); + selectFreq[3].text=i18n("weeks"); + let selectMode=document.getElementById("defaultMode").options; + selectMode[0].text=i18n("modeM0"); + selectMode[1].text=i18n("modeM3"); + selectMode[2].text=i18n("modeM4"); + selectMode[3].text=i18n("modeM1"); + selectMode[4].text=i18n("modeM2"); + document.getElementById("labelDefaultIgnoreNumbers").textContent=i18n("defaultIgnoreNumbers"); + document.getElementById("labelDefaultDeleteScripts").textContent=i18n("defaultDeleteScripts"); + document.getElementById("labelDefaultDeleteComments").textContent=i18n("defaultDeleteComments"); + document.getElementById("labelDefaultIgnoreHrefs").textContent=i18n("defaultIgnoreHrefs"); document.body.removeAttribute("class"); } diff --git a/src/shared.js b/src/shared.js index 8bf7f2c..a7a9869 100644 --- a/src/shared.js +++ b/src/shared.js @@ -2,10 +2,22 @@ const extURL=browser.extension.getURL(""); -function rqstAdd(url,title,icon=false,mode="m0",freq=8,bookmarkId=false,cssSelector=false,ignoreNumbers=false,deleteScripts=true){ +function rqstAdd(url,title,icon=false,mode,freq,bookmarkId=false,cssSelector=false,ignoreNumbers,deleteScripts,deleteComments,ignoreHrefs){ if(!url)return; if(!title)title=url; getSettings().then(s=>{ + if(ignoreNumbers===undefined){ + ignoreNumbers=s.defaultIgnoreNumbers; + } + if(deleteScripts===undefined){ + deleteScripts=s.defaultDeleteScripts; + } + if(deleteComments===undefined){ + deleteComments=s.defaultDeleteComments; + } + if(ignoreHrefs===undefined){ + ignoreHrefs=s.defaultIgnoreHrefs; + } let xhr=new XMLHttpRequest(); xhr.open("GET",url); xhr.timeout=s.requestTime; @@ -13,16 +25,28 @@ function rqstAdd(url,title,icon=false,mode="m0",freq=8,bookmarkId=false,cssSelec xhr.onload=async function(){ const result=browser.storage.local.get(['sites','changes','sort']); const contentType=this.getResponseHeader("Content-Type").split(/; *charset=/i); - const html_data=(contentType[0]==="text/plain")?this.responseText.replace(/(\r\n)|\n|\r/g,"
"):deleteScripts?this.responseText.replace(/< *script\b[^<]*(?:(?!< *\/ *script *>)<[^<]*)*< *\/[ ]*script *>/gi,""):this.responseText; + + let html_data=this.responseText; + if(contentType[0]==="text/plain"){ + html_data=html_data.replace(/(\r\n)|\n|\r/g,"
"); + }else{ + if(deleteScripts===true){ + html_data=html_data.replace(/< *script\b[^<]*(?:(?!< *\/ *script *>)<[^<]*)*< *\/[ ]*script *>/gi,""); + } + if(deleteComments===true){ + html_data=html_data.replace(/)(.|\n))*-->/gi,""); + } + } + const site={ title: title, url: url, date: date(), time: time(), - mode: mode, + mode: mode||s.defaultMode, changed:false, favicon:icon?await favicon64(icon,"original"):await favicon64(url,s.faviconService), - freq: freq||8, + freq: freq||s.defaultFreq, charset:contentType[1]||s.charset, broken: 0, paused: false, @@ -32,10 +56,12 @@ function rqstAdd(url,title,icon=false,mode="m0",freq=8,bookmarkId=false,cssSelec oldTime:undefined, newTime:[date(),time()], ignoreNumbers:ignoreNumbers, - deleteScripts:deleteScripts + deleteScripts:deleteScripts, + deleteComments:deleteComments, + ignoreHrefs:ignoreHrefs, }; - Object.assign(site,length_md5(html_data,ignoreNumbers)); - + Object.assign(site,length_md5(html_data,ignoreNumbers,ignoreHrefs)); + const {sites,changes,sort}=await result; sites[sites.length]=site; changes[changes.length]={ @@ -141,30 +167,51 @@ function scanPage(local,id,sitesLength,extraTime=false){ xhr.overrideMimeType('text/html; charset='+charset); xhr.onload=function(){ if(this.status<405){ //https://developer.mozilla.org/en-US/docs/Web/HTTP/Status - const html_data=(local.mimeType==="text/plain")?this.responseText.replace(/(\r\n)|\n|\r/g,"
"):(local.deleteScripts===true)?this.responseText.replace(/< *script\b[^<]*(?:(?!< *\/ *script *>)<[^<]*)*< *\/[ ]*script *>/gi,""):this.responseText; + let html_data=this.responseText; + if(local.mimeType==="text/plain"){ + html_data=html_data.replace(/(\r\n)|\n|\r/g,"
"); + }else{ + if(local.deleteScripts===true){ + html_data=html_data.replace(/< *script\b[^<]*(?:(?!< *\/ *script *>)<[^<]*)*< *\/[ ]*script *>/gi,""); + } + if(local.deleteComments===true){ + html_data=html_data.replace(/)(.|\n))*-->/gi,""); + } + } + + if(typeof local.ignoreHrefs==="undefined"){ + Object.assign(local,{ignoreHrefs:s.defaultIgnoreHrefs}); + } + let scanned; if(!local.paritialMode||!local.cssSelector){ - scanned=length_md5(html_data,local.ignoreNumbers); + scanned=length_md5(html_data,local.ignoreNumbers,local.ignoreHrefs); }else{ let parser=new DOMParser(), doc=parser.parseFromString(html_data,"text/html"), selectedElement=doc.querySelector(local.cssSelector); if(selectedElement){ let partHTML=selectedElement.outerHTML; - scanned=length_md5(partHTML,local.ignoreNumbers); + scanned=length_md5(partHTML,local.ignoreNumbers,local.ignoreHrefs); }else{ - scanned=length_md5(html_data,local.ignoreNumbers); + scanned=length_md5(html_data,local.ignoreNumbers,local.ignoreHrefs); } } - + if((local.mode==="m0"&&(Math.abs(local.length-scanned.length)>=10))||(local.mode==="m3"&&(Math.abs(local.length-scanned.length)>=50))||(local.mode==="m4"&&(Math.abs(local.length-scanned.length)>=250))||(local.mode==="m1"&&local.length!==scanned.length)||(local.mode==="m2"&&local.md5!==scanned.md5)){ browser.runtime.sendMessage({"addClass":true,"elementId":"item"+id,"classList":["changed","scanned"]}); browser.runtime.sendMessage({"addClass":true,"elementId":"item"+id,"classList":["changedFolder"],"parentElement":true}); count++; - if(typeof local.deleteScripts==="undefined"){ - const htmlWithoutScripts=html_data.replace(/< *script\b[^<]*(?:(?!< *\/ *script *>)<[^<]*)*< *\/[ ]*script *>/gi,""); - scanned=length_md5(htmlWithoutScripts,local.ignoreNumbers); - changesArray[id]=[htmlWithoutScripts,scanned.md5,scanned.length]; + if(typeof local.deleteScripts==="undefined"||typeof local.deleteComments==="undefined"){ //workaround + let htmlReplaced=html_data; + if(typeof local.deleteScripts==="undefined"&&s.defaultDeleteScripts===true){ + htmlReplaced=htmlReplaced.replace(/< *script\b[^<]*(?:(?!< *\/ *script *>)<[^<]*)*< *\/[ ]*script *>/gi,""); + } + if(typeof local.deleteComments==="undefined"&&s.defaultDeleteComments===true){ + htmlReplaced=htmlReplaced.replace(/)(.|\n))*-->/gi,""); + } + scanned=length_md5(htmlReplaced,local.ignoreNumbers,local.ignoreHrefs); + changesArray[id]=[htmlReplaced,scanned.md5,scanned.length]; }else{ changesArray[id]=[html_data,scanned.md5,scanned.length]; } @@ -258,7 +305,7 @@ function deltaTime(oldDate,oldTime){ } async function updateBase(){ - const {sites,changes}=await browser.storage.local.get(['sites','changes']); + const {sites,changes,settings}=await browser.storage.local.get(['sites','changes','settings']); let currentTime={ date:date(), time:time(), @@ -281,7 +328,13 @@ async function updateBase(){ }; Object.assign(sites[id],obj); if(typeof sites[id].deleteScripts==="undefined"){ - Object.assign(sites[id],{deleteScripts:true}); + Object.assign(sites[id],{deleteScripts:settings.defaultDeleteScripts}); + } + if(typeof sites[id].deleteComments==="undefined"){ + Object.assign(sites[id],{deleteComments:settings.defaultDeleteComments}); + } + if(typeof sites[id].ignoreHrefs==="undefined"){ + Object.assign(sites[id],{ignoreHrefs:settings.defaultIgnoreHrefs}); } }); timesArray.forEach((value,id)=>{ @@ -424,7 +477,12 @@ async function updateTooltip(alarm){ } } -function length_md5(html,ignoreNumbers){ - const htmlNumber=ignoreNumbers?html.replace(/\d+/g,''):html; - return {length:htmlNumber.length,md5:md5(htmlNumber)}; +function length_md5(html,ignoreNumbers,ignoreHrefs){ + if(ignoreNumbers){ + html=html.replace(/\d+/g,""); + } + if(ignoreHrefs){ + html=html.replace(/href=(["'])(.*?)\1/g,"href=''"); + } + return {length:html.length,md5:md5(html)}; } diff --git a/src/sidebar.html b/src/sidebar.html index df839c8..da81165 100644 --- a/src/sidebar.html +++ b/src/sidebar.html @@ -40,7 +40,9 @@ + + @@ -75,7 +77,9 @@ + + diff --git a/src/sidebar.js b/src/sidebar.js index e5265aa..970b1ce 100644 --- a/src/sidebar.js +++ b/src/sidebar.js @@ -431,12 +431,13 @@ function deleteFolder(id){ async function showEdit(e){ hideAll("edit"); let result=await browser.storage.local.get(['sites','settings']); - const table=result.sites; + const table=result.sites, + settings=result.settings; document.getElementById("editSite").dataset.id=e; document.getElementById("editingSite").classList.remove("hidden"); document.getElementById("eUrl").value=table[e].url; document.getElementById("eTitle").value=table[e].title; - document.getElementById("eCharset").value=table[e].charset?table[e].charset:result.settings.charset; + document.getElementById("eCharset").value=table[e].charset?table[e].charset:settings.charset; const freq=table[e].freq; let multi; if(!(freq%168)) @@ -451,7 +452,9 @@ async function showEdit(e){ document.getElementById("eMulti").value=multi; document.getElementById("eMode").value=table[e].mode; document.getElementById("eIgnoreNumbers").checked=table[e].ignoreNumbers; - document.getElementById("eDeleteScripts").checked=table[e].deleteScripts; + document.getElementById("eIgnoreHrefs").checked=(table[e].ignoreHrefs===undefined)?settings.defaultIgnoreHrefs:table[e].ignoreHrefs; + document.getElementById("eDeleteScripts").checked=(table[e].deleteScripts===undefined)?settings.defaultDeleteScripts:table[e].deleteScripts; + document.getElementById("eDeleteComments").checked=(table[e].deleteComments===undefined)?settings.defaultDeleteComments:table[e].deleteComments; document.getElementById("rowSelectorE").className=table[e].paritialMode?"":"hidden"; document.getElementById("eParitialMode").checked=table[e].paritialMode; document.getElementById("eCssSelector").value=(table[e].cssSelector===undefined)?"":table[e].cssSelector; @@ -471,7 +474,9 @@ function editSite(e){ paritialMode:document.getElementById("eParitialMode").checked, cssSelector:document.getElementById("eCssSelector").value, ignoreNumbers:document.getElementById("eIgnoreNumbers").checked, - deleteScripts:document.getElementById("eDeleteScripts").checked + ignoreHrefs:document.getElementById("eIgnoreHrefs").checked, + deleteScripts:document.getElementById("eDeleteScripts").checked, + deleteComments:document.getElementById("eDeleteComments").checked, }; Object.assign(sites[e],obj); browser.storage.local.set({sites}).then(()=>{ @@ -518,19 +523,34 @@ function deleteSite(e){ } function showAdd(){ - hideAll("add"); - document.getElementById("addingSite").classList.toggle("hidden"); - document.getElementById("showAdd").classList.toggle("open"); - document.getElementById("aUrl").value=""; - document.getElementById("aTitle").value=""; - document.getElementById("aFreq").value=8; - document.getElementById("aMulti").value=1; - document.getElementById("aMode").value="m0"; - document.getElementById("aParitialMode").checked=false; - document.getElementById("aCssSelector").value=""; - document.getElementById("rowSelectorA").className="hidden"; - document.getElementById("aIgnoreNumbers").checked=false; - document.getElementById("aDeleteScripts").checked=true; + browser.storage.local.get('settings').then(result=>{ + const settings=result.settings; + const freq=settings.defaultFreq; + let unit; + if(!(freq%168)) + unit=168; + else if(!(freq%24)) + unit=24; + else if(freq<1) + unit=0.0166667; + else + unit=1; + hideAll("add"); + document.getElementById("addingSite").classList.toggle("hidden"); + document.getElementById("showAdd").classList.toggle("open"); + document.getElementById("aUrl").value=""; + document.getElementById("aTitle").value=""; + document.getElementById("aFreq").value=parseInt(freq/unit);; + document.getElementById("aMulti").value=unit; + document.getElementById("aMode").value=settings.defaultMode; + document.getElementById("aParitialMode").checked=false; + document.getElementById("aCssSelector").value=""; + document.getElementById("rowSelectorA").className="hidden"; + document.getElementById("aIgnoreNumbers").checked=settings.defaultIgnoreNumbers; + document.getElementById("aIgnoreHrefs").checked=settings.defaultIgnoreHrefs; + document.getElementById("aDeleteScripts").checked=settings.defaultDeleteScripts; + document.getElementById("aDeleteComments").checked=settings.defaultDeleteComments; + }); } function addSite(){ @@ -541,8 +561,10 @@ function addSite(){ freq=aFreq>0?aFreq*parseFloat(document.getElementById("aMulti").value):8, cssSelector=(document.getElementById("aParitialMode").checked&&document.getElementById("aCssSelector").value.length)?document.getElementById("aCssSelector").value:false, ignoreNumbers=document.getElementById("aIgnoreNumbers").checked, - deleteScripts=document.getElementById("aDeleteScripts").checked; - browser.runtime.sendMessage({"addThis":true,"url":url,"title":title,"mode":mode,"freq":freq,"cssSelector":cssSelector,"ignoreNumbers":ignoreNumbers,"deleteScripts":deleteScripts}); + ignoreHrefs=document.getElementById("aIgnoreHrefs").checked, + deleteScripts=document.getElementById("aDeleteScripts").checked, + deleteComments=document.getElementById("aDeleteComments").checked; + browser.runtime.sendMessage({"addThis":true,"url":url,"title":title,"mode":mode,"freq":freq,"cssSelector":cssSelector,"ignoreNumbers":ignoreNumbers,"deleteScripts":deleteScripts,"deleteComments":deleteComments,"ignoreHrefs":ignoreHrefs}); document.getElementById("addingSite").classList.add("hidden"); document.getElementById("showAdd").classList.remove("open"); } @@ -820,8 +842,12 @@ function translate(){ document.getElementById("inspectE").title=i18n("inspectElement"); document.getElementById("ignoreNumbersA").textContent=i18n("ignoreNumbers"); document.getElementById("ignoreNumbersE").textContent=i18n("ignoreNumbers"); + document.getElementById("ignoreHrefsA").textContent=i18n("ignoreHrefs"); + document.getElementById("ignoreHrefsE").textContent=i18n("ignoreHrefs"); document.getElementById("deleteScriptsA").textContent=i18n("deleteScripts"); document.getElementById("deleteScriptsE").textContent=i18n("deleteScripts"); + document.getElementById("deleteCommentsA").textContent=i18n("deleteComments"); + document.getElementById("deleteCommentsE").textContent=i18n("deleteComments"); document.getElementById("pageSettings").textContent=i18n("options"); let selectMultiA=document.getElementById("aMulti").options; diff --git a/src/view.html b/src/view.html index a8d97ce..4c98cbc 100644 --- a/src/view.html +++ b/src/view.html @@ -62,7 +62,9 @@

+
+
diff --git a/src/view.js b/src/view.js index 5a15a4f..4fc34ad 100644 --- a/src/view.js +++ b/src/view.js @@ -123,13 +123,12 @@ function deleteSite(){ function showEdit(){ document.getElementById("deletePopup").classList.add("hidden"); - browser.storage.local.get(['sites','settings']).then(result=>{ - const sites=result.sites; + browser.storage.local.get(['sites','settings']).then(({sites,settings})=>{ document.getElementById("editOk").addEventListener("click",editSite); document.getElementById("editPopup").classList.remove("hidden"); document.getElementById("urlEdit").value=sites[localId].url; document.getElementById("titleEdit").value=sites[localId].title; - document.getElementById("charsetEdit").value=sites[localId].charset?sites[localId].charset:result.settings.charset; + document.getElementById("charsetEdit").value=sites[localId].charset?sites[localId].charset:settings.charset; const freq=sites[localId].freq; let unit; if(!(freq%168)) @@ -144,7 +143,9 @@ function showEdit(){ document.getElementById("unitEdit").value=unit; document.getElementById("modeEdit").value=sites[localId].mode; document.getElementById("ignoreNumbersEdit").checked=sites[localId].ignoreNumbers; - document.getElementById("deleteScriptsEdit").checked=sites[localId].deleteScripts; + document.getElementById("ignoreHrefsEdit").checked=(sites[localId].ignoreHrefs===undefined)?settings.defaultIgnoreHrefs:sites[localId].ignoreHrefs; + document.getElementById("deleteScriptsEdit").checked=(sites[localId].deleteScripts===undefined)?settings.defaultDeleteScripts:sites[localId].deleteScripts; + document.getElementById("deleteCommentsEdit").checked=(sites[localId].deleteComments===undefined)?settings.defaultDeleteComments:sites[localId].deleteComments; document.getElementById("spanSelectorEdit").className=sites[localId].paritialMode?"":"notVisible"; document.getElementById("cssSelectorLabelEdit").className=sites[localId].paritialMode?"":"notVisible"; document.getElementById("paritialModeEdit").checked=sites[localId].paritialMode; @@ -182,7 +183,9 @@ function editSite(){ paritialMode:document.getElementById("paritialModeEdit").checked, cssSelector:document.getElementById("cssSelectorEdit").value, ignoreNumbers:document.getElementById("ignoreNumbersEdit").checked, - deleteScripts:document.getElementById("deleteScriptsEdit").checked + ignoreHrefs:document.getElementById("ignoreHrefsEdit").checked, + deleteScripts:document.getElementById("deleteScriptsEdit").checked, + deleteComments:document.getElementById("deleteCommentsEdit").checked, } const pageSettings={ defaultView: document.getElementById("defaultView").value, @@ -204,6 +207,17 @@ function editSite(){ }); } +function partHtml(html,selectorCss){ + let parser=new DOMParser(), + doc=parser.parseFromString(html,"text/html"), + selectedElement=doc.querySelector(selectorCss); + if(selectedElement){ + return selectedElement.outerHTML; + }else{ + return html; + } +} + function load(type,inspectMode){ browser.storage.local.get(['sites','changes','settings']).then(result=>{ const sites=result.sites, @@ -213,25 +227,7 @@ function load(type,inspectMode){ cId=changes[localId], newHtml=cId.html, oldHtml=cId?cId.oldHtml:"", - diffStringX=settings.diffOld?diffString2old:diffString2, - diffString=diffStringX(oldHtml,newHtml), - light=cId?diffString.n:newHtml, - news=cId?diffString.c:"", - deleted=cId?diffString.o:"", - url=sId.url.split("/"), - url2=url[0]+"//"+url[2]+"/", - lastScan=[realDate(sId.date),realTime(sId.time)], - oldTime=sId.oldTime?[realDate(sId.oldTime[0])," "+realTime(sId.oldTime[1])]:"", - newTime=sId.newTime?[realDate(sId.newTime[0])," "+realTime(sId.newTime[1])]:""; - let parser=new DOMParser(), - doc; - if(oldHtml)enableBtn("oldHtml"); - if(news)enableBtn("news"); - if(deleted)enableBtn("deleted"); - toggleNextPrev(); - toggleScrollbarMarkers(); - highlighted=undefined; - prevHighlighted=undefined; + diffStringX=settings.diffOld?diffString2old:diffString2; const pageSettings={ defaultView:0, @@ -249,12 +245,38 @@ function load(type,inspectMode){ pageSettings[e[0]]=sId.settings[e[0]] } }); + type=type||pageSettings.defaultView; + + let diffString; + if((type==="raw"||type==="news"||type==="deleted")&&sId.paritialMode&&sId.cssSelector&&!pageSettings.highlightOutsideChanges){ + diffString=diffStringX(partHtml(oldHtml,sId.cssSelector),partHtml(newHtml,sId.cssSelector)); + }else{ + diffString=diffStringX(oldHtml,newHtml); + } + + const light=cId?diffString.n:newHtml, + news=cId?diffString.c:"", + deleted=cId?diffString.o:"", + url=sId.url.split("/"), + url2=url[0]+"//"+url[2]+"/", + lastScan=[realDate(sId.date),realTime(sId.time)], + oldTime=sId.oldTime?[realDate(sId.oldTime[0])," "+realTime(sId.oldTime[1])]:"", + newTime=sId.newTime?[realDate(sId.newTime[0])," "+realTime(sId.newTime[1])]:""; + let parser=new DOMParser(), + doc; + if(oldHtml)enableBtn("oldHtml"); + if(news)enableBtn("news"); + if(deleted)enableBtn("deleted"); + toggleNextPrev(); + toggleScrollbarMarkers(); + highlighted=undefined; + prevHighlighted=undefined; + if(pageSettings.hideHeader){ toggleHeader(true); }else if(document.body.classList.contains("hiddenHeader")){ toggleHeader(); } - type=type||pageSettings.defaultView; document.getElementById("viewMode").value=type; switch(type){ case "light": @@ -450,7 +472,9 @@ function translate(){ document.getElementById("cssSelectorLabelEdit").textContent=i18n("selectorCSS"); document.getElementById("inspectButtonEdit").title=i18n("inspectElement"); document.getElementById("ignoreNumbersLabelEdit").textContent=i18n("ignoreNumbers"); + document.getElementById("ignoreHrefsLabelEdit").textContent=i18n("ignoreHrefs"); document.getElementById("deleteScriptsLabelEdit").textContent=i18n("deleteScripts"); + document.getElementById("deleteCommentsLabelEdit").textContent=i18n("deleteComments"); document.getElementById("optionsH2").textContent=i18n("options"); document.getElementById("labelDefaultView").textContent=i18n("defaultView"); let defaultViewSelect=document.getElementById("defaultView").options;