|
|
|
@ -13,12 +13,28 @@ function getCurrentTabUrl(callback) { |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function replaceBookmark(oldUrl, newUrl) { |
|
|
|
|
chrome.bookmarks.search({url: oldUrl}, function(bookmarks) { |
|
|
|
|
for(bookmark of bookmarks) { |
|
|
|
|
chrome.bookmarks.update(bookmark.id, {url: newUrl});
|
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function copyToClipboard(url) { |
|
|
|
|
document.oncopy = function(event) { |
|
|
|
|
event.clipboardData.setData("text/plain", url); |
|
|
|
|
event.preventDefault(); |
|
|
|
|
}; |
|
|
|
|
document.execCommand('Copy', false, null); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
chrome.pageAction.onClicked.addListener(function(tab) { |
|
|
|
|
getCurrentTabUrl(function(url) { |
|
|
|
|
var filename = url.substr(url.lastIndexOf("/")); |
|
|
|
|
|
|
|
|
|
chrome.storage.sync.get({url: '', behaviour: ''}, function(items) { |
|
|
|
|
if(items.url == '') { |
|
|
|
|
chrome.storage.sync.get({url: '', tabbehaviour: '', copytoclipboard: false, replacebookmark: false}, function(config) { |
|
|
|
|
if(config.url == '') { |
|
|
|
|
alert("Please select a Pomf clone."); |
|
|
|
|
chrome.tabs.create({ url: "options.html" }); |
|
|
|
|
return; |
|
|
|
@ -27,10 +43,10 @@ chrome.pageAction.onClicked.addListener(function(tab) { |
|
|
|
|
var worker = new Worker('worker.js'); |
|
|
|
|
worker.onmessage = function(event) { |
|
|
|
|
var response = JSON.parse(event.data); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var newUrl = response.files[0].url; |
|
|
|
|
|
|
|
|
|
switch(items.behaviour) |
|
|
|
|
switch(config.tabbehaviour) |
|
|
|
|
{ |
|
|
|
|
case "newtab": |
|
|
|
|
chrome.tabs.create({url: newUrl}); |
|
|
|
@ -39,8 +55,16 @@ chrome.pageAction.onClicked.addListener(function(tab) { |
|
|
|
|
chrome.tabs.update({url: newUrl}); |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if(config.copytoclipboard) { |
|
|
|
|
copyToClipboard(newUrl);
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if(config.replacebookmark) { |
|
|
|
|
replaceBookmark(url, newUrl); |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
worker.postMessage(JSON.stringify({pomfclone: items.url, url: url, filename: filename}));
|
|
|
|
|
worker.postMessage(JSON.stringify({pomfclone: config.url, url: url, filename: filename}));
|
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|