Skip to content

Commit 4b64b18

Browse files
v1.0
1 parent 707df85 commit 4b64b18

5 files changed

Lines changed: 110 additions & 0 deletions

File tree

background.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
updateurls(); setInterval(updateurls, 10000);
2+
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
27+
});
28+
}
29+
});
30+
31+
function updateurls() {
32+
if(localStorage.getItem("urls")) urls = localStorage.getItem("urls").split(',');
33+
else urls = [];
34+
}

icon.png

51.5 KB
Loading

manifest.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
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",
6+
"background": {
7+
"scripts": ["background.js"]
8+
},
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+
}

popup.html

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<script src="/popup.js"></script>
5+
<link href='https://fonts.googleapis.com/css?family=Exo' rel='stylesheet'>
6+
<style>
7+
html {
8+
height: 300px;
9+
width: 200px;
10+
}
11+
body {
12+
font-family: Exo;
13+
text-align: center;
14+
background-color: #eeeeee;
15+
}
16+
#textarea {
17+
height: 250px;
18+
resize: none;
19+
}
20+
#discards {
21+
cursor: pointer;
22+
}
23+
</style>
24+
</head>
25+
<body>
26+
<b>Do Not Discard:</b><br>
27+
<textarea autofocus spellcheck="false" placeholder="Examples:&#10;mail.google.com&#10;bing.com&#10;&#10;Note: this applies to both HTTP and HTTPS, to subdomains, and to all pages inside them.&#10;&#10;Do not use slashes or asterisks; just insert domains or subdomains." id="textarea"></textarea>
28+
<br><b id="discards"><u>Open chrome://discards</u></b>
29+
</body>
30+
</html>

popup.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
window.onload = function() {
2+
3+
value = localStorage.getItem("value");
4+
document.getElementById("textarea").value = value;
5+
6+
document.getElementById("textarea").onkeyup = function() {
7+
if(document.getElementById("textarea").value.length === 0) {
8+
localStorage.removeItem("urls");
9+
localStorage.removeItem("value");
10+
return;
11+
}
12+
localStorage.setItem("value", document.getElementById("textarea").value);
13+
array = document.getElementById("textarea").value.split("\n");
14+
for (i = 0; i < array.length; i++) {
15+
array[i] = "*://" + array[i] + "/*";
16+
if(i === array.length-1)
17+
localStorage.setItem("urls", array)
18+
}
19+
}
20+
21+
document.getElementById("discards").onclick = function() {
22+
chrome.tabs.create({url: "chrome://discards"})
23+
}
24+
25+
}

0 commit comments

Comments
 (0)