diff --git a/background.js b/background.js new file mode 100644 index 0000000..86e9ce4 --- /dev/null +++ b/background.js @@ -0,0 +1,22 @@ +chrome.action.onClicked.addListener((tab) => { + chrome.scripting.executeScript({ + target: { tabId: tab.id }, + function: reloadStylesheetsAndScripts, + }); +}); + +function reloadStylesheetsAndScripts() { + var queryString = '?reload=' + new Date().getTime(); + + // Reload stylesheets + document.querySelectorAll('link[rel="stylesheet"], link[rel="stylesheet preload"]').forEach(function (link) { + link.href = link.href.replace(/\?.*|$/, queryString); + }); + + // Reload scripts + document.querySelectorAll('script').forEach(function (script) { + if (script.src) { + script.src = script.src.replace(/\?.*|$/, queryString); + } + }); +} diff --git a/images/.DS_Store b/images/.DS_Store new file mode 100644 index 0000000..d14f678 Binary files /dev/null and b/images/.DS_Store differ diff --git a/images/icon128.png b/images/icon128.png new file mode 100644 index 0000000..a8b4a71 Binary files /dev/null and b/images/icon128.png differ diff --git a/images/icon16.png b/images/icon16.png new file mode 100644 index 0000000..2498096 Binary files /dev/null and b/images/icon16.png differ diff --git a/images/icon48.png b/images/icon48.png new file mode 100644 index 0000000..b0c48c0 Binary files /dev/null and b/images/icon48.png differ diff --git a/manifest.json b/manifest.json new file mode 100644 index 0000000..203f78f --- /dev/null +++ b/manifest.json @@ -0,0 +1,23 @@ +{ + "manifest_version": 3, + "name": "CSS and JS Reload", + "version": "1.0", + "description": "Extension to reload CSS and JavaScript on a webpage.", + "permissions": ["activeTab", "scripting"], + "background": { + "service_worker": "background.js" + }, + "action": { + "default_popup": "popup.html", + "default_icon": { + "16": "images/icon16.png", + "48": "images/icon48.png", + "128": "images/icon128.png" + } + }, + "icons": { + "16": "images/icon16.png", + "48": "images/icon48.png", + "128": "images/icon128.png" + } +} diff --git a/popup.css b/popup.css new file mode 100644 index 0000000..8468868 --- /dev/null +++ b/popup.css @@ -0,0 +1,13 @@ +body { + width: 244px; +} +body button { + width: 100px; + margin: 10px; + padding: 10px; + border: none; + color: white; + background: purple; +} + +/*# sourceMappingURL=popup.css.map */ diff --git a/popup.css.map b/popup.css.map new file mode 100644 index 0000000..1c67a6e --- /dev/null +++ b/popup.css.map @@ -0,0 +1 @@ +{"version":3,"sourceRoot":"","sources":["popup.scss"],"names":[],"mappings":"AAAA;EACE;;AACA;EACE;EACA;EACA;EACA;EACA;EACA","file":"popup.css"} \ No newline at end of file diff --git a/popup.html b/popup.html new file mode 100644 index 0000000..7d209dd --- /dev/null +++ b/popup.html @@ -0,0 +1,15 @@ + + + + Reload CSS and JS + + + + + + + + diff --git a/popup.js b/popup.js new file mode 100644 index 0000000..694fe1d --- /dev/null +++ b/popup.js @@ -0,0 +1,41 @@ +document.addEventListener('DOMContentLoaded', function () { + var reloadCssButton = document.getElementById('reloadCss'); + if (reloadCssButton) { + reloadCssButton.addEventListener('click', () => { + chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) { + chrome.scripting.executeScript({ + target: { tabId: tabs[0].id }, + function: reloadStylesheets, + }); + }); + }); + } + + var reloadJsButton = document.getElementById('reloadJs'); + if (reloadJsButton) { + reloadJsButton.addEventListener('click', () => { + chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) { + chrome.scripting.executeScript({ + target: { tabId: tabs[0].id }, + function: reloadScripts, + }); + }); + }); + } +}); + +function reloadStylesheets() { + var queryString = '?reload=' + new Date().getTime(); + document.querySelectorAll('link[rel="stylesheet"], link[rel="stylesheet preload"]').forEach(function (link) { + link.href = link.href.replace(/\?.*|$/, queryString); + }); +} + +function reloadScripts() { + var queryString = '?reload=' + new Date().getTime(); + document.querySelectorAll('script').forEach(function (script) { + if (script.src) { + script.src = script.src.replace(/\?.*|$/, queryString); + } + }); +} diff --git a/popup.scss b/popup.scss new file mode 100644 index 0000000..567423e --- /dev/null +++ b/popup.scss @@ -0,0 +1,11 @@ +body { + width: 244px; + button { + width: 100px; + margin: 10px; + padding: 10px; + border: none; + color: white; + background: purple; + } +}