-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
107 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,29 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<title>Favicon Chameleon. Makes your tab disappear when nobody is paying attention.</title> | ||
|
||
<meta charset="utf-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
<head> | ||
<title>Favicon Chameleon. Makes your tab disappear when nobody is paying attention.</title> | ||
|
||
<link href="favicons/default.ico" rel="shortcut icon" type="image/x-icon"> | ||
<meta charset="utf-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
|
||
<link rel="stylesheet" href="style.css"> | ||
<link href="favicons/default.ico" rel="shortcut icon" type="image/x-icon"> | ||
|
||
<script src="script.js" defer></script> | ||
<link rel="stylesheet" href="style.css"> | ||
<script src="script.js" defer></script> | ||
|
||
<script type="text/javascript"> | ||
window.onload = () => { | ||
new Chameleon(['mastodon', 'bluesky', 'gmail', 'tumblr']) | ||
} | ||
</script> | ||
</head> | ||
|
||
<body> | ||
<p> | ||
Ok, now jump to another tab. | ||
</p> | ||
</body> | ||
|
||
<script type="text/javascript"> | ||
window.onload = () => { | ||
new Chameleon(['twitter', 'gmail', 'tumblr']) | ||
} | ||
</script> | ||
</head> | ||
<body> | ||
<p> | ||
Ok, now jump to another tab. | ||
</p> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,111 +1,130 @@ | ||
const SERVICES = { | ||
const SERVICES = { | ||
tumblr: () => { | ||
let title = 'Tumblr' | ||
let favicon = 'favicons/tumblr.ico' | ||
let title = "Tumblr"; | ||
let favicon = "favicons/tumblr.ico"; | ||
|
||
return { | ||
title, favicon | ||
} | ||
title, | ||
favicon, | ||
}; | ||
}, | ||
|
||
twitter: () => { | ||
let title = 'Twitter' | ||
let favicon = 'favicons/twitter.ico' | ||
mastodon: () => { | ||
let title = "Home - Mastodon"; | ||
let favicon = "favicons/mastodon.png"; | ||
|
||
return { | ||
title, favicon | ||
} | ||
title, | ||
favicon, | ||
}; | ||
}, | ||
|
||
bluesky: () => { | ||
let title = "Following — Bluesky"; | ||
let favicon = "favicons/bluesky.png"; | ||
|
||
return { | ||
title, | ||
favicon, | ||
}; | ||
}, | ||
|
||
gmail: () => { | ||
let title = 'Inbox' | ||
let count = Math.round(Math.random() * 12) | ||
let emailCount = count | ||
let gmailIcon = 'favicons/gmail_' | ||
let title = "Inbox"; | ||
let count = Math.round(Math.random() * 12); | ||
let emailCount = count; | ||
let gmailIcon = "favicons/gmail_"; | ||
|
||
if (count === 11) { | ||
count = 50 | ||
emailCount = `${count}+` | ||
count = 50; | ||
emailCount = `${count}+`; | ||
} else if (count === 12) { | ||
count = 100 | ||
emailCount = `${count}+` | ||
count = 100; | ||
emailCount = `${count}+`; | ||
} | ||
|
||
let favicon = `${gmailIcon}${count}.png` | ||
let favicon = `${gmailIcon}${count}.png`; | ||
|
||
if (emailCount) { | ||
title = `Inbox (${emailCount})` | ||
title = `Inbox (${emailCount})`; | ||
} | ||
|
||
return { | ||
title, favicon | ||
} | ||
} | ||
} | ||
title, | ||
favicon, | ||
}; | ||
}, | ||
}; | ||
|
||
class Chameleon { | ||
constructor (enabledServices) { | ||
this.enabledServices = enabledServices | ||
this.services = SERVICES | ||
this.hidden = 'hidden' | ||
this.visibilityChange = 'visibilitychange' | ||
|
||
this.favicon = document.querySelector("[rel='shortcut icon']").href | ||
this.title = document.title | ||
this.init() | ||
constructor(enabledServices) { | ||
this.enabledServices = enabledServices; | ||
this.services = SERVICES; | ||
this.hidden = "hidden"; | ||
this.visibilityChange = "visibilitychange"; | ||
|
||
this.favicon = document.querySelector("[rel='shortcut icon']").href; | ||
this.title = document.title; | ||
|
||
this.init(); | ||
} | ||
|
||
init () { | ||
if (typeof document.mozHidden !== 'undefined') { | ||
this.hidden = 'mozHidden' | ||
this.visibilityChange = 'mozvisibilitychange' | ||
} else if (typeof document.msHidden !== 'undefined') { | ||
this.hidden = 'msHidden' | ||
this.visibilityChange = 'msvisibilitychange' | ||
} else if (typeof document.webkitHidden !== 'undefined') { | ||
this.hidden = 'webkitHidden' | ||
this.visibilityChange = 'webkitvisibilitychange' | ||
init() { | ||
if (typeof document.mozHidden !== "undefined") { | ||
this.hidden = "mozHidden"; | ||
this.visibilityChange = "mozvisibilitychange"; | ||
} else if (typeof document.msHidden !== "undefined") { | ||
this.hidden = "msHidden"; | ||
this.visibilityChange = "msvisibilitychange"; | ||
} else if (typeof document.webkitHidden !== "undefined") { | ||
this.hidden = "webkitHidden"; | ||
this.visibilityChange = "webkitvisibilitychange"; | ||
} | ||
|
||
document.addEventListener(this.visibilityChange, this.handleVisibilityChange.bind(this), false) | ||
document.addEventListener( | ||
this.visibilityChange, | ||
this.handleVisibilityChange.bind(this), | ||
false, | ||
); | ||
} | ||
|
||
setDefaultFavicon () { | ||
let title = this.title | ||
let favicon = this.favicon | ||
setDefaultFavicon() { | ||
let title = this.title; | ||
let favicon = this.favicon; | ||
|
||
this.updateFavicon({ title, favicon}) | ||
this.updateFavicon({ title, favicon }); | ||
} | ||
|
||
updateFavicon (data) { | ||
|
||
let randomString = "?v=" + Math.round(Math.random() * 10000000) | ||
let link = document.createElement('link') | ||
updateFavicon(data) { | ||
let randomString = "?v=" + Math.round(Math.random() * 10000000); | ||
let link = document.createElement("link"); | ||
|
||
link.type = 'image/x-icon' | ||
link.rel = 'shortcut icon' | ||
link.href = data.favicon + randomString | ||
link.type = "image/x-icon"; | ||
link.rel = "shortcut icon"; | ||
link.href = data.favicon + randomString; | ||
|
||
document.getElementsByTagName('head')[0].querySelector("[rel='shortcut icon']").remove() | ||
document.getElementsByTagName('head')[0].appendChild(link) | ||
document.title = data.title | ||
document | ||
.getElementsByTagName("head")[0] | ||
.querySelector("[rel='shortcut icon']") | ||
.remove(); | ||
document.getElementsByTagName("head")[0].appendChild(link); | ||
document.title = data.title; | ||
} | ||
|
||
enableService () { | ||
let i = Math.round(Math.random() * (this.enabledServices.length - 1)) | ||
let service = this.enabledServices[i] | ||
enableService() { | ||
let i = Math.round(Math.random() * (this.enabledServices.length - 1)); | ||
let service = this.enabledServices[i]; | ||
|
||
if (service && this.services[service]) { | ||
this.updateFavicon(this.services[service]()) | ||
this.updateFavicon(this.services[service]()); | ||
} | ||
} | ||
|
||
handleVisibilityChange () { | ||
handleVisibilityChange() { | ||
if (document[this.hidden]) { | ||
this.enableService() | ||
this.enableService(); | ||
} else { | ||
this.setDefaultFavicon() | ||
this.setDefaultFavicon(); | ||
} | ||
} | ||
} |