Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions background.js
Original file line number Diff line number Diff line change
@@ -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);
}
});
}
Binary file added images/.DS_Store
Binary file not shown.
Binary file added images/icon128.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/icon16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/icon48.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 23 additions & 0 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
13 changes: 13 additions & 0 deletions popup.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions popup.css.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions popup.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html>
<head>
<title>Reload CSS and JS</title>
<script src="popup.js"></script>
<link
rel="stylesheet"
href="popup.css"
/>
</head>
<body>
<button id="reloadJs">Reload JavaScript</button>
<button id="reloadCss">Reload CSS</button>
</body>
</html>
41 changes: 41 additions & 0 deletions popup.js
Original file line number Diff line number Diff line change
@@ -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);
}
});
}
11 changes: 11 additions & 0 deletions popup.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
body {
width: 244px;
button {
width: 100px;
margin: 10px;
padding: 10px;
border: none;
color: white;
background: purple;
}
}