preparing for v1.4
This commit is contained in:
parent
491dcb791b
commit
4a35e0ea81
|
|
@ -1,5 +1,5 @@
|
||||||
// 'use strict';
|
// 'use strict';
|
||||||
chrome.runtime.onInstalled.addListener(function() {
|
chrome.runtime.onInstalled.addListener(function () {
|
||||||
// https://stackoverflow.com/questions/19377262/regex-for-youtube-url
|
// https://stackoverflow.com/questions/19377262/regex-for-youtube-url
|
||||||
chrome.contextMenus.create({
|
chrome.contextMenus.create({
|
||||||
id: 'metube',
|
id: 'metube',
|
||||||
|
|
@ -14,16 +14,19 @@ chrome.runtime.onInstalled.addListener(function() {
|
||||||
|
|
||||||
// Set sane defaults for click behaviors at extension install time
|
// Set sane defaults for click behaviors at extension install time
|
||||||
chrome.storage.sync.set({
|
chrome.storage.sync.set({
|
||||||
"clickBehavior": "go-to-metube",
|
"clickBehavior": "send-current-url",
|
||||||
"contextMenuClickBehavior": "context-menu-send-current-url-and-switch"
|
"contextMenuClickBehavior": "context-menu-send-current-url-and-switch"
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
function sendVideoUrlToMetube(videoUrl, metubeUrl, callback) {
|
function sendVideoUrlToMetube(videoUrl, metubeUrl, callback) {
|
||||||
console.log("Sending videoUrl=" + videoUrl + " to metubeUrl=" + metubeUrl);
|
console.log("Sending videoUrl=" + videoUrl + " to metubeUrl=" + metubeUrl);
|
||||||
if (typeof callback !== 'function'){
|
|
||||||
callback = function(){};
|
if (typeof callback !== 'function') {
|
||||||
|
callback = function () {
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
fetch(metubeUrl + "/add", {
|
fetch(metubeUrl + "/add", {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
|
|
@ -35,72 +38,70 @@ function sendVideoUrlToMetube(videoUrl, metubeUrl, callback) {
|
||||||
"url": videoUrl
|
"url": videoUrl
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
.then(response=>response.json())
|
.then(response => response.json())
|
||||||
.then(function (response) {
|
.then(function (response) {
|
||||||
if (response.status === 'ok') {
|
if (response.status === 'ok') {
|
||||||
callback();
|
callback();
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
console.log("Ran into an error when submitting URL to meTube: " + response.msg);
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.catch(e => console.log("Ran into an unexpected error: " + e));
|
.catch(e => console.log("Ran into an unexpected error: " + e));
|
||||||
}
|
}
|
||||||
|
|
||||||
chrome.contextMenus.onClicked.addListener(function(item, tab) {
|
chrome.contextMenus.onClicked.addListener(function (item, tab) {
|
||||||
chrome.storage.sync.get(['metube', 'contextMenuClickBehavior'], function(data) {
|
chrome.storage.sync.get(['metube', 'contextMenuClickBehavior'], function (data) {
|
||||||
if (data === undefined || !data.hasOwnProperty('metube') || data.metube === "") {
|
if (data === undefined || !data.hasOwnProperty('metube') || data.metube === "") {
|
||||||
openTab(chrome.runtime.getURL('options.html'), tab);
|
openTab(chrome.runtime.getURL('options.html'), tab);
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
let needToSwitch = (data.contextMenuClickBehavior === 'context-menu-send-current-url-and-switch');
|
let needToSwitch = (data.contextMenuClickBehavior === 'context-menu-send-current-url-and-switch');
|
||||||
sendVideoUrlToMetube(item.linkUrl, data.metube, function() {
|
|
||||||
if (!needToSwitch) {
|
sendVideoUrlToMetube(item.linkUrl, data.metube, function () {
|
||||||
return;
|
if (needToSwitch) {
|
||||||
}
|
|
||||||
openTab(data.metube, tab);
|
openTab(data.metube, tab);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
chrome.action.onClicked.addListener(function(tab) {
|
chrome.action.onClicked.addListener(function (tab) {
|
||||||
chrome.storage.sync.get(['metube', 'clickBehavior'], function(data) {
|
chrome.storage.sync.get(['metube', 'clickBehavior'], function (data) {
|
||||||
if (data === undefined || !data.hasOwnProperty('metube') || data.metube === "") {
|
if (data === undefined || !data.hasOwnProperty('metube') || data.metube === "") {
|
||||||
openTab(chrome.runtime.getURL('options.html'), tab);
|
openTab(chrome.runtime.getURL('options.html'), tab);
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
let needToSwitch = (data.clickBehavior === 'send-current-url-and-switch');
|
|
||||||
if (data.clickBehavior == 'do-nothing') {
|
if (data.clickBehavior === 'go-to-metube') {
|
||||||
return
|
|
||||||
} else if (data.clickBehavior == 'go-to-metube') {
|
|
||||||
console.log("Going to Metube URL...");
|
|
||||||
openTab(data.metube, tab);
|
openTab(data.metube, tab);
|
||||||
} else {
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let needToSwitch = (data.clickBehavior === 'send-current-url-and-switch');
|
||||||
|
|
||||||
chrome.tabs.query({
|
chrome.tabs.query({
|
||||||
active: true,
|
active: true,
|
||||||
lastFocusedWindow: true
|
lastFocusedWindow: true
|
||||||
}, function(tabs) {
|
}, function (tabs) {
|
||||||
// use this tab to get the youtube video URL
|
// use this tab to get the youtube video URL
|
||||||
let videoUrl = tabs[0].url;
|
let videoUrl = tabs[0].url;
|
||||||
sendVideoUrlToMetube(videoUrl, data.metube, function() {
|
sendVideoUrlToMetube(videoUrl, data.metube, function () {
|
||||||
if (!needToSwitch) {
|
if (!needToSwitch) {
|
||||||
return;
|
|
||||||
}
|
|
||||||
openTab(data.metube, tab);
|
openTab(data.metube, tab);
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
function openTab(url, currentTab) {
|
function openTab(url, currentTab) {
|
||||||
chrome.tabs.query({
|
chrome.tabs.query({
|
||||||
url: url + "/*"
|
url: url + "/*"
|
||||||
}, function(tabs) {
|
}, function (tabs) {
|
||||||
if (tabs.length !== 0) {
|
if (tabs.length !== 0) {
|
||||||
chrome.tabs.update(tabs[0].id, {
|
chrome.tabs.update(tabs[0].id, {
|
||||||
'active': true
|
'active': true
|
||||||
}, () => {});
|
}, () => {
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
chrome.tabs.create({
|
chrome.tabs.create({
|
||||||
url: url,
|
url: url,
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,6 @@
|
||||||
<br>
|
<br>
|
||||||
|
|
||||||
<h4>When you left-click on the extension icon, you'd like it to:</h4>
|
<h4>When you left-click on the extension icon, you'd like it to:</h4>
|
||||||
<input type="radio" name="click-behavior" id="do-nothing" value="do-nothing"><label for="do-nothing">Do Nothing</label><br>
|
|
||||||
<input type="radio" name="click-behavior" id="go-to-metube" value="go-to-metube"><label for="go-to-metube">Go to MeTube URL</label><br>
|
<input type="radio" name="click-behavior" id="go-to-metube" value="go-to-metube"><label for="go-to-metube">Go to MeTube URL</label><br>
|
||||||
<input type="radio" name="click-behavior" id="send-current-url" value="send-current-url"><label for="send-current-url">Send current tab URL to MeTube (no tab switch)</label><br>
|
<input type="radio" name="click-behavior" id="send-current-url" value="send-current-url"><label for="send-current-url">Send current tab URL to MeTube (no tab switch)</label><br>
|
||||||
<input type="radio" name="click-behavior" id="send-current-url-and-switch" value="send-current-url-and-switch"><label for="send-current-url-and-switch">Send current tab URL to MeTube and switch to MeTube</label><br>
|
<input type="radio" name="click-behavior" id="send-current-url-and-switch" value="send-current-url-and-switch"><label for="send-current-url-and-switch">Send current tab URL to MeTube and switch to MeTube</label><br>
|
||||||
|
|
|
||||||
|
|
@ -6,9 +6,7 @@ async function saveOptions() {
|
||||||
}
|
}
|
||||||
|
|
||||||
let sites = document.getElementById("additional").value;
|
let sites = document.getElementById("additional").value;
|
||||||
|
|
||||||
let clickBehavior = document.querySelector('input[name="click-behavior"]:checked').value;
|
let clickBehavior = document.querySelector('input[name="click-behavior"]:checked').value;
|
||||||
|
|
||||||
let contextMenuClickBehavior = document.querySelector('input[name="context-menu-click-behavior"]:checked').value;
|
let contextMenuClickBehavior = document.querySelector('input[name="context-menu-click-behavior"]:checked').value;
|
||||||
|
|
||||||
chrome.storage.sync.set({
|
chrome.storage.sync.set({
|
||||||
|
|
@ -54,19 +52,20 @@ async function restoreOptions() {
|
||||||
'clickBehavior',
|
'clickBehavior',
|
||||||
'contextMenuClickBehavior'
|
'contextMenuClickBehavior'
|
||||||
], function (data) {
|
], function (data) {
|
||||||
if (data.metube != undefined) {
|
if (data.metube !== undefined) {
|
||||||
document.getElementById("metube").value = data.metube;
|
document.getElementById("metube").value = data.metube;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data.sites != undefined) {
|
if (data.sites !== undefined) {
|
||||||
document.getElementById("additional").value = data.sites;
|
document.getElementById("additional").value = data.sites;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data.clickBehavior != undefined) {
|
alert(data.clickBehavior);
|
||||||
|
if (data.clickBehavior !== undefined) {
|
||||||
document.getElementById(data.clickBehavior).checked = true;
|
document.getElementById(data.clickBehavior).checked = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data.contextMenuClickBehavior != undefined) {
|
if (data.contextMenuClickBehavior !== undefined) {
|
||||||
document.getElementById(data.contextMenuClickBehavior).checked = true;
|
document.getElementById(data.contextMenuClickBehavior).checked = true;
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue