Add copying to clipboard and replacing bookmarks
This commit is contained in:
parent
447b0b6db2
commit
997e826002
|
@ -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) {
|
chrome.pageAction.onClicked.addListener(function(tab) {
|
||||||
getCurrentTabUrl(function(url) {
|
getCurrentTabUrl(function(url) {
|
||||||
var filename = url.substr(url.lastIndexOf("/"));
|
var filename = url.substr(url.lastIndexOf("/"));
|
||||||
|
|
||||||
chrome.storage.sync.get({url: '', behaviour: ''}, function(items) {
|
chrome.storage.sync.get({url: '', tabbehaviour: '', copytoclipboard: false, replacebookmark: false}, function(config) {
|
||||||
if(items.url == '') {
|
if(config.url == '') {
|
||||||
alert("Please select a Pomf clone.");
|
alert("Please select a Pomf clone.");
|
||||||
chrome.tabs.create({ url: "options.html" });
|
chrome.tabs.create({ url: "options.html" });
|
||||||
return;
|
return;
|
||||||
|
@ -27,10 +43,10 @@ chrome.pageAction.onClicked.addListener(function(tab) {
|
||||||
var worker = new Worker('worker.js');
|
var worker = new Worker('worker.js');
|
||||||
worker.onmessage = function(event) {
|
worker.onmessage = function(event) {
|
||||||
var response = JSON.parse(event.data);
|
var response = JSON.parse(event.data);
|
||||||
|
|
||||||
var newUrl = response.files[0].url;
|
var newUrl = response.files[0].url;
|
||||||
|
|
||||||
switch(items.behaviour)
|
switch(config.tabbehaviour)
|
||||||
{
|
{
|
||||||
case "newtab":
|
case "newtab":
|
||||||
chrome.tabs.create({url: newUrl});
|
chrome.tabs.create({url: newUrl});
|
||||||
|
@ -39,8 +55,16 @@ chrome.pageAction.onClicked.addListener(function(tab) {
|
||||||
chrome.tabs.update({url: newUrl});
|
chrome.tabs.update({url: newUrl});
|
||||||
break;
|
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}));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
"tabs",
|
"tabs",
|
||||||
"storage",
|
"storage",
|
||||||
"http://*/*",
|
"http://*/*",
|
||||||
"https://*/*"
|
"https://*/*",
|
||||||
|
"bookmarks"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
15
options.html
15
options.html
|
@ -21,25 +21,30 @@
|
||||||
<br />
|
<br />
|
||||||
|
|
||||||
URL:
|
URL:
|
||||||
<input type="textbox" id="urlbox">
|
<input type="text" id="urlbox">
|
||||||
|
|
||||||
<br />
|
<br />
|
||||||
<br />
|
<br />
|
||||||
|
|
||||||
After upload:<br />
|
After upload:<br />
|
||||||
<input type="radio" name="behaviour" id="newtab" value="newtab" checked> Open new tab<br />
|
<input type="radio" name="tabbehaviour" id="newtab" value="newtab" checked> Open new tab<br />
|
||||||
<input type="radio" name="behaviour" id="replacetab" value="replacetab"> Replace current tab
|
<input type="radio" name="tabbehaviour" id="replacetab" value="replacetab"> Replace current tab
|
||||||
|
|
||||||
|
<br />
|
||||||
|
<br />
|
||||||
|
|
||||||
|
<input type="checkbox" id="copytoclipboard"> Copy URL to clipboard<br />
|
||||||
|
<input type="checkbox" id="replacebookmark"> Replace bookmark (if original URL is bookmarked)
|
||||||
|
|
||||||
<br />
|
<br />
|
||||||
<br />
|
<br />
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
TODO:
|
TODO:
|
||||||
* Add URL to clipboard (checkbox)
|
|
||||||
* Replace old bookmark (checkbox)
|
|
||||||
* Disable blacklist (checkbox)
|
* Disable blacklist (checkbox)
|
||||||
* Add imageboard thread archival support
|
* Add imageboard thread archival support
|
||||||
* Add booru support
|
* Add booru support
|
||||||
|
* Error checks and messages
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<button id="save">Save</button>
|
<button id="save">Save</button>
|
||||||
|
|
27
options.js
27
options.js
|
@ -26,13 +26,17 @@ function setUrlBox() {
|
||||||
function saveOptions() {
|
function saveOptions() {
|
||||||
var pomfclone = document.getElementById('pomfclone').value;
|
var pomfclone = document.getElementById('pomfclone').value;
|
||||||
var url = document.getElementById('urlbox').value;
|
var url = document.getElementById('urlbox').value;
|
||||||
var behaviour = document.querySelector('input[name="behaviour"]:checked').value;
|
var tabbehaviour = document.querySelector('input[name="tabbehaviour"]:checked').value;
|
||||||
|
var copytoclipboard = document.getElementById('copytoclipboard').checked;
|
||||||
|
var replacebookmark = document.getElementById('replacebookmark').checked;
|
||||||
|
|
||||||
chrome.storage.sync.set({
|
chrome.storage.sync.set({
|
||||||
pomfclone: pomfclone,
|
pomfclone: pomfclone,
|
||||||
url: url,
|
url: url,
|
||||||
customUrl: customUrl,
|
customUrl: customUrl,
|
||||||
behaviour: behaviour
|
tabbehaviour: tabbehaviour,
|
||||||
|
copytoclipboard: copytoclipboard,
|
||||||
|
replacebookmark: replacebookmark
|
||||||
}, function() {
|
}, function() {
|
||||||
var status = document.getElementById('status');
|
var status = document.getElementById('status');
|
||||||
status.textContent = 'Options saved.';
|
status.textContent = 'Options saved.';
|
||||||
|
@ -49,15 +53,20 @@ function restoreOptions() {
|
||||||
pomfclone: firstPomfclone.innerHTML,
|
pomfclone: firstPomfclone.innerHTML,
|
||||||
url: firstPomfclone.value,
|
url: firstPomfclone.value,
|
||||||
customUrl: '',
|
customUrl: '',
|
||||||
behaviour: document.querySelector('input[name="behaviour"]:checked').value
|
tabbehaviour: document.querySelector('input[name="tabbehaviour"]:checked').value,
|
||||||
}, function(items) {
|
copytoclipboard: false,
|
||||||
document.getElementById('pomfclone').value = items.pomfclone;
|
replacebookmark: false
|
||||||
document.getElementById('urlbox').value = items.url;
|
}, function(config) {
|
||||||
customUrl = items.customUrl;
|
document.getElementById('pomfclone').value = config.pomfclone;
|
||||||
custom = items.pomfclone == "custom";
|
document.getElementById('urlbox').value = config.url;
|
||||||
|
customUrl = config.customUrl;
|
||||||
|
custom = config.pomfclone == "custom";
|
||||||
setUrlBox();
|
setUrlBox();
|
||||||
|
|
||||||
document.getElementById(items.behaviour).checked = true;
|
document.getElementById(config.tabbehaviour).checked = true;
|
||||||
|
|
||||||
|
document.getElementById('copytoclipboard').checked = config.copytoclipboard;
|
||||||
|
document.getElementById('replacebookmark').checked = config.replacebookmark;
|
||||||
});
|
});
|
||||||
|
|
||||||
document.getElementById('status').textContent = '';
|
document.getElementById('status').textContent = '';
|
||||||
|
|
Loading…
Reference in New Issue