diff --git a/icons/icon-128.png b/icons/icon-128.png new file mode 100644 index 0000000..8f419dd Binary files /dev/null and b/icons/icon-128.png differ diff --git a/icons/icon-32.png b/icons/icon-32.png new file mode 100644 index 0000000..c9f8ac0 Binary files /dev/null and b/icons/icon-32.png differ diff --git a/icons/icon-48.png b/icons/icon-48.png new file mode 100644 index 0000000..3319205 Binary files /dev/null and b/icons/icon-48.png differ diff --git a/icons/icon-96.png b/icons/icon-96.png new file mode 100644 index 0000000..1512acf Binary files /dev/null and b/icons/icon-96.png differ diff --git a/manifest.json b/manifest.json new file mode 100644 index 0000000..cec6a90 --- /dev/null +++ b/manifest.json @@ -0,0 +1,35 @@ +{ + "name": "Picture", + "version": "0.1", + "manifest_version": 2, + "description": "Redirects all instagram URLs to smihub.com or picuki.com per user choice", + + "icons": { + "48": "icons/icon-48.png", + "96": "icons/icon-96.png", + "128": "icons/icon-128.png" + }, + + "browser_action": { + "default_title": "Picture", + "default_icon": "icons/icon-32.png", + "default_popup": "popup/options.html" + }, + + "browser_specific_settings": { + "gecko": { + "id": "@ansh3ll.picture" + } + }, + + "background": { + "scripts": ["picture.js"] + }, + + "permissions": [ + "storage", + "webRequest", + "webRequestBlocking", + "*://*.instagram.com/*" + ] +} \ No newline at end of file diff --git a/picture.js b/picture.js new file mode 100644 index 0000000..06c654c --- /dev/null +++ b/picture.js @@ -0,0 +1,70 @@ +//smihub +const smihub = 'https://smihub.com/'; +const postPrefixS = 'https://smihub.com/c/'; +const profilePrefixS = 'https://smihub.com/v/'; +//picuki +const picuki = 'https://www.picuki.com/'; +const postPrefixP = 'https://www.picuki.com/media/'; +const profilePrefixP = 'https://www.picuki.com/profile/'; +//regex +const postRegex = /(? { + mediaId = BigInt((mediaId * 64n)) + BigInt(alphabet.indexOf(letter)); + }); + return mediaId.toString().split('').reverse().join(''); +} + +function setPrefix(result) { + prefix = result.handler; + if(prefix == 1 || prefix == 2) { + document.igRequestHandler = prefix; + if(!browser.webRequest.onBeforeRequest.hasListener(igRedirect)) { + browser.webRequest.onBeforeRequest.addListener(igRedirect, filter, ['blocking']); + } + } else if(browser.webRequest.onBeforeRequest.hasListener(igRedirect)) { + browser.webRequest.onBeforeRequest.removeListener(igRedirect); + } +} + +function loadPreferences(changes, areaName) { + pref = browser.storage.local.get('handler'); + pref.then((result) => {setPrefix(result);}, (error) => {}); +} + +function igRedirect(details) { + if(document.igRequestHandler == 1) { + redirectTo = smihub; + postPrefix = postPrefixS; + profilePrefix = profilePrefixS; + } else if(document.igRequestHandler == 2) { + redirectTo = picuki; + postPrefix = postPrefixP; + profilePrefix = profilePrefixP; + } + // + if(postRegex.test(decodeURIComponent(details.url))) { + url = postPrefix + getMediaId(details.url); + } else if(profileRegex.test(decodeURIComponent(details.url))) { + url = profilePrefix + getUsername(details.url); + } else { + return {redirectUrl: redirectTo}; + } + return {redirectUrl: url}; +} + +browser.storage.onChanged.addListener(loadPreferences); +browser.webRequest.onBeforeRequest.addListener(igRedirect, filter, ['blocking']); \ No newline at end of file diff --git a/popup/options.html b/popup/options.html new file mode 100644 index 0000000..93e5434 --- /dev/null +++ b/popup/options.html @@ -0,0 +1,14 @@ + + + + + + +

Status: Using smihub.com

+ + + +

Icon made by Freepik from www.flaticon.com

+ + + \ No newline at end of file diff --git a/popup/options.js b/popup/options.js new file mode 100644 index 0000000..314267d --- /dev/null +++ b/popup/options.js @@ -0,0 +1,43 @@ +function savePreferences(pref) { + browser.storage.local.set({handler: pref}); +} + +function loadPreferences() { + pref = browser.storage.local.get('handler'); + pref.then((result) => {updateUi(result);}, (error) => {displayError();}); +} + +function updateUi(result) { + pref = result.handler; + if(pref == 1) { + document.getElementById('status').innerHTML = 'Status: Using smihub.com'; + } else if(pref == 2) { + document.getElementById('status').innerHTML = 'Status: Using picuki.com'; + } else { + document.getElementById('status').innerHTML = 'Status: Disabled'; + } +} + +function displayError() { + document.getElementById('status').innerHTML = 'Status: Error resolving handler'; +} + +function setSmihub() { + savePreferences(1); + loadPreferences(); +} + +function setPicuki() { + savePreferences(2); + loadPreferences(); +} + +function setDisabled() { + savePreferences(3); + loadPreferences(); +} + +document.addEventListener('DOMContentLoaded', loadPreferences); +document.getElementById('smihub').addEventListener('click', setSmihub); +document.getElementById('picuki').addEventListener('click', setPicuki); +document.getElementById('disabled').addEventListener('click', setDisabled); \ No newline at end of file