commit b313bc85f307d3c104e46f598f827c0a8c7ccce0 Author: Rpsl Date: Tue Jan 26 16:22:56 2021 +0300 🚀 first release diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..81cf67a --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.idea/ +*.mov \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..0296cd3 --- /dev/null +++ b/README.md @@ -0,0 +1,22 @@ + +Chrome MeTube Downloader +======= + +![example]() + +Use the context menu to send youtube video into [MeTube](https://github.com/alexta69/metube) + +Installation from store +----- + +- ~~Google Chrome~~ not available at now. Possible later + +Installation from sources +----- +- Download this repository +- Open "[Extensions](chrome://extensions/)" tab +- Turn On "developer mode" in top right corner +- Click "Load unpacked extension" +- Choose folder with sources of repository + + diff --git a/attach/metube-dowloader.gif b/attach/metube-dowloader.gif new file mode 100644 index 0000000..1905e0e Binary files /dev/null and b/attach/metube-dowloader.gif differ diff --git a/background.js b/background.js new file mode 100644 index 0000000..598ba40 --- /dev/null +++ b/background.js @@ -0,0 +1,46 @@ +'use strict'; + +chrome.runtime.onInstalled.addListener(function () { + // https://stackoverflow.com/questions/19377262/regex-for-youtube-url + chrome.contextMenus.create({ + id: 'metube', + title: "Send to MeTube", + documentUrlPatterns: [ + 'https://www.youtube.com/*', + 'https://m.youtube.com/*', + 'https://youtu.be/*' + ], + contexts: ['link'], + }); +}); + +chrome.contextMenus.onClicked.addListener(function (item, tab) { + chrome.storage.sync.get(['metube'], function (data) { + if(data === undefined || !data.hasOwnProperty('metube') ){ + // todo notify user about settings + return + } + + let url = data.metube; + let xhr = new XMLHttpRequest(); + xhr.open("POST", url + "/add", true); + xhr.setRequestHeader("Content-Type", "application/json"); + xhr.onreadystatechange = function () { + if (xhr.readyState === 4 && xhr.status === 200) { + let json = JSON.parse(xhr.responseText); + if (json.status === "ok") { + chrome.tabs.query({url: url + "/*"}, function (tabs) { + if (tabs.length !== 0) { + chrome.tabs.update(tabs[0].id, {'active': true}, () => {}); + } else { + chrome.tabs.create({url: url, index: tab.index + 1}); + } + }); + } else { + alert("error :: " + json); + } + } + }; + xhr.send(JSON.stringify({"quality": "best", "url": item.linkUrl})); + }); +}); diff --git a/icon128.png b/icon128.png new file mode 100644 index 0000000..1c7e98b Binary files /dev/null and b/icon128.png differ diff --git a/icon16.png b/icon16.png new file mode 100644 index 0000000..bdb9934 Binary files /dev/null and b/icon16.png differ diff --git a/icon48.png b/icon48.png new file mode 100644 index 0000000..b55c294 Binary files /dev/null and b/icon48.png differ diff --git a/manifest.json b/manifest.json new file mode 100644 index 0000000..4a5cf4e --- /dev/null +++ b/manifest.json @@ -0,0 +1,25 @@ +{ + "name": "MeTube Downloader", + "description": "Use the context menu to send video into MeTube application", + "version": "1.0", + "manifest_version": 2, + "permissions": ["contextMenus", "storage", "tabs"], + "background": { + "scripts": [ + "background.js" + ], + "persistent": false + }, + "options_ui": { + "page": "options.html", + "browser_style": true + }, + "browser_action": { + "default_popup": "options.html" + }, + "icons": { + "16": "icon16.png", + "48": "icon48.png", + "128": "icon128.png" + } +} diff --git a/options.html b/options.html new file mode 100644 index 0000000..b991c2a --- /dev/null +++ b/options.html @@ -0,0 +1,35 @@ + + + + MeTube Downloader + + + + +

About

+

This extension is context menu button for sending links of youtube videos into you own instance of MeTube

+

This extension won't work without installed MeTube. For additional instructions see github page of MeTube.

+

If you have some throubles with extension you can open issue on github page of extension.

+

 

+

Settings

+
+ + + +
+ + + diff --git a/options.js b/options.js new file mode 100644 index 0000000..fc9dc9e --- /dev/null +++ b/options.js @@ -0,0 +1,28 @@ +async function saveOptions() { + let url = document.getElementById("metube").value; + + if (url.endsWith('/')) { + url = url.slice(0, -1) + } + + chrome.storage.sync.set({"metube": url}, function () { + document.getElementById("saved").classList.remove('hidden'); + + setTimeout(function () { + document.getElementById("saved").classList.add('hidden'); + }, 1000 * 10) + }); +} + +async function restoreOptions() { + chrome.storage.sync.get(['metube'], function (data) { + document.getElementById("metube").value = data.metube; + }); +} + +window.addEventListener("DOMContentLoaded", restoreOptions, {passive: true}); + +document.querySelector("form").addEventListener("submit", (e) => { + e.preventDefault(); + saveOptions(); +}, {passive: false});