Skip to content

Commit 408a8cb

Browse files
v1.0.2 (Renamed to Disable automatic tab discarding)
1 parent 4b64b18 commit 408a8cb

4 files changed

Lines changed: 27 additions & 102 deletions

File tree

background.js

Lines changed: 12 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,16 @@
1-
updateurls(); setInterval(updateurls, 10000);
1+
chrome.tabs.onCreated.addListener(function(tab) {
2+
if(tab.status === "complete") chrome.tabs.reload(tab.id);
3+
chrome.tabs.update(tab.id, {autoDiscardable: false});
4+
});
25

3-
chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab){
4-
if(urls.length === 0) return;
5-
if(changeInfo.url) {
6-
chrome.tabs.query({url: urls}, function(tabs) {
7-
if(tabs === undefined) {
8-
updateurls();
9-
chrome.browserAction.setBadgeText({text: "error"});
10-
return;
11-
}
12-
chrome.browserAction.setBadgeText({text: ""});
13-
if(tabs.length === 0 && !(tab.autoDiscardable)) {
14-
chrome.tabs.update(tabId, {autoDiscardable: true});
15-
}
16-
if(tabs.length !== 0) {
17-
for (i = 0; i < tabs.length; i++) {
18-
if(tabs[i].id === tabId) {
19-
if(tab.autoDiscardable) // If tab matches URL pattern and it should be marked as non discardable
20-
chrome.tabs.update(tabId, {autoDiscardable: false});
21-
break;
22-
}
23-
if(i === tabs.length-1 && !(tab.autoDiscardable)) // If tab does not match URL pattern and should be marked as discardable
24-
chrome.tabs.update(tabId, {autoDiscardable: true});
25-
} // Loop
26-
} // If tabs found
6+
chrome.runtime.onInstalled.addListener(function(details) {
7+
chrome.tabs.query({}, function(tabs) {
8+
tabs.forEach(function(tab) {
9+
chrome.tabs.update(tab.id, {autoDiscardable: false});
2710
});
28-
}
11+
});
2912
});
3013

31-
function updateurls() {
32-
if(localStorage.getItem("urls")) urls = localStorage.getItem("urls").split(',');
33-
else urls = [];
34-
}
14+
chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
15+
if(changeInfo.discarded) chrome.tabs.reload(tabId);
16+
});

manifest.json

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
11
{
2-
"manifest_version":2,
3-
"name":"Do Not Discard",
4-
"description":"Avoid Chrome automatically discarding tabs that it thinks don't interest to you when they do.",
5-
"version":"1.0",
2+
"manifest_version": 2,
3+
"name": "Disable automatic tab discarding",
4+
"description": "Stops Chrome from suspending tabs, and reloading them when you switch to them — works like chrome://flags/#automatic-tab-discarding",
5+
"version": "1.0.2",
66
"background": {
77
"scripts": ["background.js"]
88
},
9-
"browser_action":{
10-
"default_popup":"popup.html",
11-
"default_icon":"icon.png"
12-
},
13-
"icons":{
14-
"16":"icon.png",
15-
"48":"icon.png",
16-
"128":"icon.png"
17-
},
18-
"permissions":[
19-
"tabs"
20-
]
21-
}
9+
"browser_action": {
10+
"default_title": "Automatic tab discarding currently disabled\nDisable/uninstall this extension to enable it",
11+
"default_icon":"icon.png"
12+
},
13+
"icons": {
14+
"16":"icon.png",
15+
"48":"icon.png",
16+
"128":"icon.png"
17+
},
18+
"permissions": []
19+
}

popup.html

Lines changed: 0 additions & 30 deletions
This file was deleted.

popup.js

Lines changed: 0 additions & 25 deletions
This file was deleted.

0 commit comments

Comments
 (0)