From 9223aa377abb3a4649c92686614ec62b4796f8ec Mon Sep 17 00:00:00 2001 From: Bjorn Stromberg Date: Sun, 22 Apr 2018 12:36:49 +0900 Subject: [PATCH] v1.2.0 - 2018-04-22 --- .gitignore | 1 + CHANGELOG.md | 4 +++ background.js | 75 ++++++++++++++++++++++++++------------------------- manifest.json | 2 +- 4 files changed, 45 insertions(+), 37 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c4c4ffc --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.zip diff --git a/CHANGELOG.md b/CHANGELOG.md index f17547b..ce614ba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Intercept Redirect +## 1.2.0 +- Reorganize list of sites so each site is listed once +- Add gitignore + ## 1.1.0 - Add plus.url.google.com - Update CHANGELOG format diff --git a/background.js b/background.js index 39cb494..b8b810c 100644 --- a/background.js +++ b/background.js @@ -1,55 +1,58 @@ const sites = { - 'exit.sc': function (q) { - return q.url; + 'exit.sc': { + pathname: '', + key: 'url' }, - 'l.facebook.com': function (q) { - return q.u; + 'l.facebook.com': { + pathname: 'l.php', + key: 'u' }, - 'plus.url.google.com': function (q) { - return q.url; + 'plus.url.google.com': { + pathname: 'url', + key: 'url' }, - 'www.google.com': function (q) { - return q.url; + 'www.google.com': { + pathname: 'url', + key: 'url' }, - 'l.instagram.com': function (q) { - return q.u; + 'l.instagram.com': { + pathname: '', + key: 'u' }, - 'l.messenger.com': function (q) { - return q.u; + 'l.messenger.com': { + pathname: 'l.php', + key: 'u' }, - 'slack-redir.net': function (q) { - return q.url; + 'slack-redir.net': { + pathname: 'link', + key: 'url' }, - 'steamcommunity.com': function (q) { - return q.url; + 'steamcommunity.com': { + pathname: 'linkfilter/', + key: 'url' }, - 't.umblr.com': function (q) { - return q.z; + 't.umblr.com': { + pathname: 'redirect', + key: 'z' }, - 'vk.com': function (q) { - return q.to; + 'vk.com': { + pathname: 'away.php', + key: 'to' }, - 'www.youtube.com': function (q) { - return q.q; + 'www.youtube.com': { + pathname: 'redirect', + key: 'q' } }; -const urls = [ - 'https://exit.sc/*', - 'https://l.facebook.com/l.php*', - 'https://plus.url.google.com/url*', - 'https://www.google.com/url*', - 'https://l.instagram.com/*', - 'https://l.messenger.com/l.php*', - 'https://slack-redir.net/link*', - 'https://steamcommunity.com/linkfilter/*', - 'https://t.umblr.com/redirect*', - 'https://vk.com/away.php*', - 'https://www.youtube.com/redirect*' -]; +const urls = Object.keys(sites).map(function(host) { + return `https://${host}/${sites[host].pathname}*`; +}); chrome.webRequest.onBeforeRequest.addListener(function(request) { const url = new URL(request.url); + const site = sites[url.host]; + const pairs = url.search.slice(1).split('&'); const q = pairs.reduce((o, pair) => { @@ -58,7 +61,7 @@ chrome.webRequest.onBeforeRequest.addListener(function(request) { return o; }, {}); - const redirectUrl = sites[url.host](q); + const redirectUrl = q[site.key]; if (redirectUrl) { return { redirectUrl }; diff --git a/manifest.json b/manifest.json index ecd1394..dfe5e5e 100644 --- a/manifest.json +++ b/manifest.json @@ -19,5 +19,5 @@ "https://vk.com/", "https://www.youtube.com/" ], - "version": "1.1.0" + "version": "1.2.0" }