From 0111a3c5ce7a43296043333061044979ea8c1be3 Mon Sep 17 00:00:00 2001 From: Noah Shanaberger Date: Sat, 9 Oct 2021 02:56:54 -0700 Subject: [PATCH] Bug fixes --- background.js | 6 +++++- content_script.js | 41 +++++++++++++++++++++++++++-------------- manifest.json | 12 +++++++----- 3 files changed, 39 insertions(+), 20 deletions(-) diff --git a/background.js b/background.js index 22ea349..47f9a18 100644 --- a/background.js +++ b/background.js @@ -1 +1,5 @@ -chrome.runtime.onMessage.addListener((r) => chrome.downloads.download({'url': r})); \ No newline at end of file +chrome.runtime.onMessage.addListener(function (url) { + chrome.downloads.download({ + 'url': url + }); +}); \ No newline at end of file diff --git a/content_script.js b/content_script.js index 3b35e5d..87afbcc 100644 --- a/content_script.js +++ b/content_script.js @@ -1,14 +1,27 @@ -const raw = document.getElementById('raw-url'); -if (raw) { - const el = document.createElement('button'); - const bar = raw.parentElement.parentElement.lastChild.previousSibling; - bar.insertBefore(el, bar.firstChild); - el.innerHTML = ''; - el.onclick = () => { - chrome.runtime.sendMessage(window.location.protocol + window.location.host + raw.getAttribute('href')); - }; - el.setAttribute('data-platforms', 'windows,mac'); - el.setAttribute('aria-label', 'Download this file'); - el.setAttribute('id', 'raw-dl'); - el.classList.add('btn-octicon', 'tooltipped', 'tooltipped-nw', 'js-remove-unless-platform'); -} \ No newline at end of file +function run() { + console.log("Running the stuff!"); + if (document.getElementById('raw-dl')) { + return; + } + console.log("Does not exist!"); + const raw = document.getElementById('raw-url'); + if (raw) { + console.log("Raw exists."); + const el = document.createElement('button'); + el.innerHTML = ''; + el.onclick = function () { + chrome.runtime.sendMessage(window.location.protocol + window.location.host + raw.getAttribute('href')); + }; + el.setAttribute('data-platforms', 'windows,mac'); + el.setAttribute('aria-label', 'Download this file'); + el.setAttribute('id', 'raw-dl'); + el.classList.add('btn-octicon', 'tooltipped', 'tooltipped-nw', 'js-remove-unless-platform'); + const bar = raw.parentElement.parentElement.lastChild.previousSibling; + bar.insertBefore(el, bar.firstChild); + } +} +document.addEventListener('pjax:success', function () { + run(); +}); + +run(); \ No newline at end of file diff --git a/manifest.json b/manifest.json index 94f2cbf..adaa34a 100644 --- a/manifest.json +++ b/manifest.json @@ -1,18 +1,20 @@ { "name": "Let's Get!", "description": "Download those pesky raw files on Github!", - "manifest_version": 3, - "version": "0.0.1", + "manifest_version": 2, + "version": "0.0.2", "background": { - "service_worker": "background.js" + "scripts": ["background.js"], + "persistent": true }, "content_scripts": [ { - "matches": ["https://github.com/*/blob/*"], + "matches": ["*://github.com/*"], "js": ["content_script.js"] } ], "permissions": [ - "downloads" + "downloads", + "*://github.com/*" ] }