From ce55fdaef656382f71959df8accea1a3c8fa4710 Mon Sep 17 00:00:00 2001 From: christianesperar Date: Mon, 9 Jul 2018 00:09:35 +0800 Subject: [PATCH] Add option page --- dist/manifest.json | 2 +- dist/search.js | 2 +- src/manifest.json | 4 ++++ src/options/options.html | 18 ++++++++++++++++++ src/options/options.js | 33 +++++++++++++++++++++++++++++++++ src/search.js | 8 +++++++- 6 files changed, 64 insertions(+), 3 deletions(-) create mode 100644 src/options/options.html create mode 100644 src/options/options.js diff --git a/dist/manifest.json b/dist/manifest.json index 1cb9804..d197d93 100644 --- a/dist/manifest.json +++ b/dist/manifest.json @@ -1 +1 @@ -{"name":"Remove Most Visited Pages","short_name":"RMVP","description":"Remove Most Visited Pages by redirecting the new tab page to Google homepage","icons":{"16":"icons/16.png","48":"icons/48.png","128":"icons/128.png"},"author":"Christian Esperar","version":"2.1.0","incognito":"split","chrome_url_overrides":{"newtab":"blank.html"},"manifest_version":2,"content_scripts":[{"matches":["*://www.google.com/*","*://www.google.ad/*","*://www.google.ae/*","*://www.google.com.af/*","*://www.google.com.ag/*","*://www.google.com.ai/*","*://www.google.al/*","*://www.google.am/*","*://www.google.co.ao/*","*://www.google.com.ar/*","*://www.google.as/*","*://www.google.at/*","*://www.google.com.au/*","*://www.google.az/*","*://www.google.ba/*","*://www.google.com.bd/*","*://www.google.be/*","*://www.google.bf/*","*://www.google.bg/*","*://www.google.com.bh/*","*://www.google.bi/*","*://www.google.bj/*","*://www.google.com.bn/*","*://www.google.com.bo/*","*://www.google.com.br/*","*://www.google.bs/*","*://www.google.bt/*","*://www.google.co.bw/*","*://www.google.by/*","*://www.google.com.bz/*","*://www.google.ca/*","*://www.google.cd/*","*://www.google.cf/*","*://www.google.cg/*","*://www.google.ch/*","*://www.google.ci/*","*://www.google.co.ck/*","*://www.google.cl/*","*://www.google.cm/*","*://www.google.cn/*","*://www.google.com.co/*","*://www.google.co.cr/*","*://www.google.com.cu/*","*://www.google.cv/*","*://www.google.com.cy/*","*://www.google.cz/*","*://www.google.de/*","*://www.google.dj/*","*://www.google.dk/*","*://www.google.dm/*","*://www.google.com.do/*","*://www.google.dz/*","*://www.google.com.ec/*","*://www.google.ee/*","*://www.google.com.eg/*","*://www.google.es/*","*://www.google.com.et/*","*://www.google.fi/*","*://www.google.com.fj/*","*://www.google.fm/*","*://www.google.fr/*","*://www.google.ga/*","*://www.google.ge/*","*://www.google.gg/*","*://www.google.com.gh/*","*://www.google.com.gi/*","*://www.google.gl/*","*://www.google.gm/*","*://www.google.gp/*","*://www.google.gr/*","*://www.google.com.gt/*","*://www.google.gy/*","*://www.google.com.hk/*","*://www.google.hn/*","*://www.google.hr/*","*://www.google.ht/*","*://www.google.hu/*","*://www.google.co.id/*","*://www.google.ie/*","*://www.google.co.il/*","*://www.google.im/*","*://www.google.co.in/*","*://www.google.iq/*","*://www.google.is/*","*://www.google.it/*","*://www.google.je/*","*://www.google.com.jm/*","*://www.google.jo/*","*://www.google.co.jp/*","*://www.google.co.ke/*","*://www.google.com.kh/*","*://www.google.ki/*","*://www.google.kg/*","*://www.google.co.kr/*","*://www.google.com.kw/*","*://www.google.kz/*","*://www.google.la/*","*://www.google.com.lb/*","*://www.google.li/*","*://www.google.lk/*","*://www.google.co.ls/*","*://www.google.lt/*","*://www.google.lu/*","*://www.google.lv/*","*://www.google.com.ly/*","*://www.google.co.ma/*","*://www.google.md/*","*://www.google.me/*","*://www.google.mg/*","*://www.google.mk/*","*://www.google.ml/*","*://www.google.com.mm/*","*://www.google.mn/*","*://www.google.ms/*","*://www.google.com.mt/*","*://www.google.mu/*","*://www.google.mv/*","*://www.google.mw/*","*://www.google.com.mx/*","*://www.google.com.my/*","*://www.google.co.mz/*","*://www.google.com.na/*","*://www.google.com.nf/*","*://www.google.com.ng/*","*://www.google.com.ni/*","*://www.google.ne/*","*://www.google.nl/*","*://www.google.no/*","*://www.google.com.np/*","*://www.google.nr/*","*://www.google.nu/*","*://www.google.co.nz/*","*://www.google.com.om/*","*://www.google.com.pa/*","*://www.google.com.pe/*","*://www.google.com.pg/*","*://www.google.com.ph/*","*://www.google.com.pk/*","*://www.google.pl/*","*://www.google.pn/*","*://www.google.com.pr/*","*://www.google.ps/*","*://www.google.pt/*","*://www.google.com.py/*","*://www.google.com.qa/*","*://www.google.ro/*","*://www.google.ru/*","*://www.google.rw/*","*://www.google.com.sa/*","*://www.google.com.sb/*","*://www.google.sc/*","*://www.google.se/*","*://www.google.com.sg/*","*://www.google.sh/*","*://www.google.si/*","*://www.google.sk/*","*://www.google.com.sl/*","*://www.google.sn/*","*://www.google.so/*","*://www.google.sm/*","*://www.google.sr/*","*://www.google.st/*","*://www.google.com.sv/*","*://www.google.td/*","*://www.google.tg/*","*://www.google.co.th/*","*://www.google.com.tj/*","*://www.google.tk/*","*://www.google.tl/*","*://www.google.tm/*","*://www.google.tn/*","*://www.google.to/*","*://www.google.com.tr/*","*://www.google.tt/*","*://www.google.com.tw/*","*://www.google.co.tz/*","*://www.google.com.ua/*","*://www.google.co.ug/*","*://www.google.co.uk/*","*://www.google.com.uy/*","*://www.google.co.uz/*","*://www.google.com.vc/*","*://www.google.co.ve/*","*://www.google.vg/*","*://www.google.co.vi/*","*://www.google.com.vn/*","*://www.google.vu/*","*://www.google.ws/*","*://www.google.rs/*","*://www.google.co.za/*","*://www.google.co.zm/*","*://www.google.co.zw/*","*://www.google.cat/*"],"css":["search.css"],"js":["search.js"],"run_at":"document_start"}]} \ No newline at end of file +{"name":"Remove Most Visited Pages","short_name":"RMVP","description":"Remove Most Visited Pages by redirecting the new tab page to Google homepage","icons":{"16":"icons/16.png","48":"icons/48.png","128":"icons/128.png"},"author":"Christian Esperar","version":"2.1.0","incognito":"split","chrome_url_overrides":{"newtab":"blank.html"},"permissions":["storage"],"options_page":"options/options.html","manifest_version":2,"content_scripts":[{"matches":["*://www.google.com/*","*://www.google.ad/*","*://www.google.ae/*","*://www.google.com.af/*","*://www.google.com.ag/*","*://www.google.com.ai/*","*://www.google.al/*","*://www.google.am/*","*://www.google.co.ao/*","*://www.google.com.ar/*","*://www.google.as/*","*://www.google.at/*","*://www.google.com.au/*","*://www.google.az/*","*://www.google.ba/*","*://www.google.com.bd/*","*://www.google.be/*","*://www.google.bf/*","*://www.google.bg/*","*://www.google.com.bh/*","*://www.google.bi/*","*://www.google.bj/*","*://www.google.com.bn/*","*://www.google.com.bo/*","*://www.google.com.br/*","*://www.google.bs/*","*://www.google.bt/*","*://www.google.co.bw/*","*://www.google.by/*","*://www.google.com.bz/*","*://www.google.ca/*","*://www.google.cd/*","*://www.google.cf/*","*://www.google.cg/*","*://www.google.ch/*","*://www.google.ci/*","*://www.google.co.ck/*","*://www.google.cl/*","*://www.google.cm/*","*://www.google.cn/*","*://www.google.com.co/*","*://www.google.co.cr/*","*://www.google.com.cu/*","*://www.google.cv/*","*://www.google.com.cy/*","*://www.google.cz/*","*://www.google.de/*","*://www.google.dj/*","*://www.google.dk/*","*://www.google.dm/*","*://www.google.com.do/*","*://www.google.dz/*","*://www.google.com.ec/*","*://www.google.ee/*","*://www.google.com.eg/*","*://www.google.es/*","*://www.google.com.et/*","*://www.google.fi/*","*://www.google.com.fj/*","*://www.google.fm/*","*://www.google.fr/*","*://www.google.ga/*","*://www.google.ge/*","*://www.google.gg/*","*://www.google.com.gh/*","*://www.google.com.gi/*","*://www.google.gl/*","*://www.google.gm/*","*://www.google.gp/*","*://www.google.gr/*","*://www.google.com.gt/*","*://www.google.gy/*","*://www.google.com.hk/*","*://www.google.hn/*","*://www.google.hr/*","*://www.google.ht/*","*://www.google.hu/*","*://www.google.co.id/*","*://www.google.ie/*","*://www.google.co.il/*","*://www.google.im/*","*://www.google.co.in/*","*://www.google.iq/*","*://www.google.is/*","*://www.google.it/*","*://www.google.je/*","*://www.google.com.jm/*","*://www.google.jo/*","*://www.google.co.jp/*","*://www.google.co.ke/*","*://www.google.com.kh/*","*://www.google.ki/*","*://www.google.kg/*","*://www.google.co.kr/*","*://www.google.com.kw/*","*://www.google.kz/*","*://www.google.la/*","*://www.google.com.lb/*","*://www.google.li/*","*://www.google.lk/*","*://www.google.co.ls/*","*://www.google.lt/*","*://www.google.lu/*","*://www.google.lv/*","*://www.google.com.ly/*","*://www.google.co.ma/*","*://www.google.md/*","*://www.google.me/*","*://www.google.mg/*","*://www.google.mk/*","*://www.google.ml/*","*://www.google.com.mm/*","*://www.google.mn/*","*://www.google.ms/*","*://www.google.com.mt/*","*://www.google.mu/*","*://www.google.mv/*","*://www.google.mw/*","*://www.google.com.mx/*","*://www.google.com.my/*","*://www.google.co.mz/*","*://www.google.com.na/*","*://www.google.com.nf/*","*://www.google.com.ng/*","*://www.google.com.ni/*","*://www.google.ne/*","*://www.google.nl/*","*://www.google.no/*","*://www.google.com.np/*","*://www.google.nr/*","*://www.google.nu/*","*://www.google.co.nz/*","*://www.google.com.om/*","*://www.google.com.pa/*","*://www.google.com.pe/*","*://www.google.com.pg/*","*://www.google.com.ph/*","*://www.google.com.pk/*","*://www.google.pl/*","*://www.google.pn/*","*://www.google.com.pr/*","*://www.google.ps/*","*://www.google.pt/*","*://www.google.com.py/*","*://www.google.com.qa/*","*://www.google.ro/*","*://www.google.ru/*","*://www.google.rw/*","*://www.google.com.sa/*","*://www.google.com.sb/*","*://www.google.sc/*","*://www.google.se/*","*://www.google.com.sg/*","*://www.google.sh/*","*://www.google.si/*","*://www.google.sk/*","*://www.google.com.sl/*","*://www.google.sn/*","*://www.google.so/*","*://www.google.sm/*","*://www.google.sr/*","*://www.google.st/*","*://www.google.com.sv/*","*://www.google.td/*","*://www.google.tg/*","*://www.google.co.th/*","*://www.google.com.tj/*","*://www.google.tk/*","*://www.google.tl/*","*://www.google.tm/*","*://www.google.tn/*","*://www.google.to/*","*://www.google.com.tr/*","*://www.google.tt/*","*://www.google.com.tw/*","*://www.google.co.tz/*","*://www.google.com.ua/*","*://www.google.co.ug/*","*://www.google.co.uk/*","*://www.google.com.uy/*","*://www.google.co.uz/*","*://www.google.com.vc/*","*://www.google.co.ve/*","*://www.google.vg/*","*://www.google.co.vi/*","*://www.google.com.vn/*","*://www.google.vu/*","*://www.google.ws/*","*://www.google.rs/*","*://www.google.co.za/*","*://www.google.co.zm/*","*://www.google.co.zw/*","*://www.google.cat/*"],"css":["search.css"],"js":["search.js"],"run_at":"document_start"}]} \ No newline at end of file diff --git a/dist/search.js b/dist/search.js index 1980a7c..ee1c592 100644 --- a/dist/search.js +++ b/dist/search.js @@ -1 +1 @@ -"use strict";var RMVP={isHomepage:function(){return"/"===window.location.pathname||1===window.location.pathname.indexOf("webhp")},toUrl:function(e){return-1===e.indexOf("//")?"//"+e:e},isUrl:function(e){return/^(?:\w+:)?\/\/([^\s\.]+\.\S{2}|localhost[\:?\d]*)\S*$/.test(e)},onLoad:function(){var e=[document.getElementsByTagName("html")[0],document.getElementById("lst-ib")];RMVP.html=e[0],RMVP.search=e[1],RMVP.search.addEventListener("keydown",function(e){if(13===(e.which||e.keyCode)){var t=RMVP.toUrl(RMVP.search.value);if(RMVP.isUrl(t))return e.preventDefault(),e.stopPropagation(),e.stopImmediatePropagation(),RMVP.html.style.display="none",window.location=t,!1}return!0})}};RMVP.isHomepage()&&document.addEventListener("DOMContentLoaded",RMVP.onLoad,!1); \ No newline at end of file +"use strict";var RMVP={isHomepage:function(){return"/"===window.location.pathname||1===window.location.pathname.indexOf("webhp")},toUrl:function(e){return-1===e.indexOf("//")?"//"+e:e},isUrl:function(e){return/^(?:\w+:)?\/\/([^\s\.]+\.\S{2}|localhost[\:?\d]*)\S*$/.test(e)},onLoad:function(){var e=[document.getElementsByTagName("html")[0],document.getElementById("lst-ib")];function t(e){if(13===(e.which||e.keyCode)){var t=RMVP.toUrl(RMVP.search.value);if(RMVP.isUrl(t))return e.preventDefault(),e.stopPropagation(),e.stopImmediatePropagation(),RMVP.html.style.display="none",window.location=t,!1}return!0}RMVP.html=e[0],RMVP.search=e[1],chrome.storage.sync.get(["RMVP_Options_UrlRedirection"],function(e){-1<[void 0,!0].indexOf(e.RMVP_Options_UrlRedirection)&&RMVP.search.addEventListener("keydown",t)})}};RMVP.isHomepage()&&document.addEventListener("DOMContentLoaded",RMVP.onLoad,!1); \ No newline at end of file diff --git a/src/manifest.json b/src/manifest.json index 6abb2c5..2190ba0 100644 --- a/src/manifest.json +++ b/src/manifest.json @@ -13,6 +13,10 @@ "chrome_url_overrides": { "newtab": "blank.html" }, + "permissions": [ + "storage" + ], + "options_page": "options/options.html", "manifest_version": 2, "content_scripts": [ { diff --git a/src/options/options.html b/src/options/options.html new file mode 100644 index 0000000..7f7b50e --- /dev/null +++ b/src/options/options.html @@ -0,0 +1,18 @@ + + + Remove Most Visited Pages Options + + + + +

Remove Most Visited Pages Options

+

+ +

+ + + + \ No newline at end of file diff --git a/src/options/options.js b/src/options/options.js new file mode 100644 index 0000000..f8953b0 --- /dev/null +++ b/src/options/options.js @@ -0,0 +1,33 @@ +const RMVPOptions = { + /** + * Attach events once DOM contents are loaded + * @return void + */ + onLoad: () => { + [RMVPOptions.inputs, RMVPOptions.button] = [ + document.getElementsByClassName('rvmp__checkbox'), + document.getElementById('rmvp__save'), + ]; + // Go directly to the website if search query is url format + const urlRedirection = RMVPOptions.inputs[0]; + + // Get options set by the user + chrome.storage.sync.get([ + 'RMVP_Options_UrlRedirection', + ], (result) => { + // Go directly to the website if search query is url format + urlRedirection.checked = [undefined, true].indexOf(result.RMVP_Options_UrlRedirection) > -1; + }); + + // Update options set by the user + RMVPOptions.button.addEventListener('click', () => { + chrome.storage.sync.set({ + RMVP_Options_UrlRedirection: urlRedirection.checked, + }, () => { + // Do something + }); + }); + }, +}; + +document.addEventListener('DOMContentLoaded', RMVPOptions.onLoad, false); diff --git a/src/search.js b/src/search.js index ecb754b..b9fb16a 100644 --- a/src/search.js +++ b/src/search.js @@ -66,7 +66,13 @@ const RMVP = { return true; } - RMVP.search.addEventListener('keydown', keyEvent); + // Get options set by the user + chrome.storage.sync.get(['RMVP_Options_UrlRedirection'], (result) => { + // Check if url redirection features is set + if ([undefined, true].indexOf(result.RMVP_Options_UrlRedirection) > -1) { + RMVP.search.addEventListener('keydown', keyEvent); + } + }); }, };