Add Twitter image support
This commit is contained in:
parent
152f54f23b
commit
f03bf7b965
|
@ -33,7 +33,7 @@ chrome.pageAction.onClicked.addListener(function(tab) {
|
||||||
getCurrentTabUrl(function(url) {
|
getCurrentTabUrl(function(url) {
|
||||||
var betterUrl = getBetterUrl(url);
|
var betterUrl = getBetterUrl(url);
|
||||||
var filename = betterUrl.substr(betterUrl.lastIndexOf("/"));
|
var filename = betterUrl.substr(betterUrl.lastIndexOf("/"));
|
||||||
filename = removeQueryString(filename);
|
filename = cleanExtension(filename);
|
||||||
|
|
||||||
chrome.storage.sync.get({url: '', tabbehaviour: '', copytoclipboard: false, replacebookmark: false}, function(config) {
|
chrome.storage.sync.get({url: '', tabbehaviour: '', copytoclipboard: false, replacebookmark: false}, function(config) {
|
||||||
if(config.url == '') {
|
if(config.url == '') {
|
||||||
|
@ -78,29 +78,41 @@ function getBetterUrl(url) {
|
||||||
var extension = url.substr(extensionIndex + 1);
|
var extension = url.substr(extensionIndex + 1);
|
||||||
|
|
||||||
if(extension == "gifv") {
|
if(extension == "gifv") {
|
||||||
return url.replace("gifv", "mp4");
|
url = url.replace("gifv", "mp4");
|
||||||
|
}
|
||||||
|
|
||||||
|
if(url.indexOf('pbs.twimg.com/media/') != -1 && url.indexOf(':orig') == -1) {
|
||||||
|
if(url.indexOf(':') != url.lastIndexOf(':')) { //Match if there are occurences of ':' other than the ':' in 'https://', such as in '.jpg:large'
|
||||||
|
url = url.substr(0, url.lastIndexOf(':'));
|
||||||
|
}
|
||||||
|
|
||||||
|
url = url + ':orig';
|
||||||
}
|
}
|
||||||
|
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
|
|
||||||
function removeQueryString(url) {
|
function cleanExtension(url) {
|
||||||
if(url.indexOf('?') != -1) {
|
var trailingStrings = ["?", ":orig"];
|
||||||
return url.substr(0, url.indexOf('?'));
|
|
||||||
} else {
|
for(trailingString of trailingStrings) {
|
||||||
return url;
|
if(url.indexOf(trailingString) != -1) {
|
||||||
|
url = url.substr(0, url.indexOf(trailingString));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return url;
|
||||||
}
|
}
|
||||||
|
|
||||||
function isCoolUrl(url) {
|
function isCoolUrl(url) {
|
||||||
url = url.toLowerCase();
|
url = url.toLowerCase();
|
||||||
|
|
||||||
var extensionIndex = url.lastIndexOf('.');
|
var extensionIndex = url.lastIndexOf('.');
|
||||||
var extension = removeQueryString(url.substr(extensionIndex + 1));
|
var extension = cleanExtension(url.substr(extensionIndex + 1));
|
||||||
|
|
||||||
var validExtensions = ["jpg", "jpeg", "png", "gif", "webm", "gifv", "mp4", "mp3", "ogg", "opus"];
|
var validExtensions = ["jpg", "jpeg", "png", "gif", "webm", "gifv", "mp4", "mp3", "ogg", "opus"];
|
||||||
|
|
||||||
var blackList = ["pomf", "mixtape.moe", "catgirlsare.sexy", "cocaine.ninja"];
|
var blackList = ["pomf.", "mixtape.moe", "catgirlsare.sexy", "cocaine.ninja"];
|
||||||
|
|
||||||
for(black of blackList) {
|
for(black of blackList) {
|
||||||
if(url.indexOf(black) != -1) {
|
if(url.indexOf(black) != -1) {
|
||||||
|
@ -120,7 +132,7 @@ chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
|
||||||
|
|
||||||
chrome.tabs.onActivated.addListener(function(activeInfo) {
|
chrome.tabs.onActivated.addListener(function(activeInfo) {
|
||||||
chrome.tabs.get(activeInfo.tabId, function(tab) {
|
chrome.tabs.get(activeInfo.tabId, function(tab) {
|
||||||
if(isCoolUrl(tab.url))
|
if(isCoolUrl(getBetterUrl(tab.url)))
|
||||||
{
|
{
|
||||||
chrome.pageAction.show(activeInfo.tabId);
|
chrome.pageAction.show(activeInfo.tabId);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue