-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
162 additions
and
0 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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/*" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 = /(?<!^https\:\/\/www\.google\.com\/imgres\?imgurl.*)(?:https?\:\/\/)?(?:www\.)?(instagram\.com|instagr\.am|next\=)(?:\/p|\/reel)\/([a-zA-Z._0-9-]+)/i; | ||
const profileRegex = /(?<!^https\:\/\/www\.google\.com\/imgres\?imgurl.*)(?:https?\:\/\/)?(?:www\.)?(?<!help\.|api\.|business\.|about\.|lookaside\.)(instagram\.com|instagr\.am|next\=)\/(?!accounts|explore|developer|reel)([a-zA-Z._0-9]{3,})/i; | ||
|
||
var filter = {urls: ["*://*.instagram.com/*"]}; | ||
|
||
function getUsername(igurl) { | ||
url = decodeURIComponent(igurl); | ||
return url.match(profileRegex)[2]; | ||
} | ||
|
||
function getMediaId(igurl) { | ||
mediaId = BigInt(0); | ||
url = decodeURIComponent(igurl); | ||
shortcode = url.match(instaPost)[2].split(''); | ||
alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_'; | ||
shortcode.forEach((letter) => { | ||
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']); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<!DOCTYPE HTML> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
</head> | ||
<body> | ||
<p id="status">Status: Using smihub.com</p> | ||
<button id="smihub">Use smihub.com</button> | ||
<button id="picuki">Use picuki.com</button> | ||
<button id="disabled">Disable Picture</button> | ||
<p>Icon made by <a href="https://www.freepik.com" title="Freepik">Freepik</a> from <a href="https://www.flaticon.com/" title="Flaticon">www.flaticon.com</a></p> | ||
<script src="options.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); |