From e471b19a5e01ff7d62f3bf52fbbe011a5dce4020 Mon Sep 17 00:00:00 2001 From: Wesley McGinn Date: Thu, 4 Apr 2024 15:28:16 -0400 Subject: [PATCH 01/63] Split settings page into popup and options The popup page will allow for basic adjustments of size, speed, colour, etc., while the options page will have the same settings and more, especially including checkboxes for what the snail may talk about. --- extension-files/manifest.json | 6 +- .../{settings.html => options.html} | 0 extension-files/popup.html | 118 ++++++++++++++++++ 3 files changed, 121 insertions(+), 3 deletions(-) rename extension-files/{settings.html => options.html} (100%) create mode 100644 extension-files/popup.html diff --git a/extension-files/manifest.json b/extension-files/manifest.json index 06b223c..946ea97 100644 --- a/extension-files/manifest.json +++ b/extension-files/manifest.json @@ -1,7 +1,7 @@ { "name" : "MySnail", "short_name" : "🐌", - "version" : "1.9.6", + "version" : "2.0.0", "manifest_version" : 3, "minimum_chrome_version" : "49", "permissions" : ["storage"], @@ -13,7 +13,7 @@ "type" : "business" }, "action" : { - "default_popup" : "settings.html", + "default_popup" : "popup.html", "default_title" : "MySnail", "default_icon" : { "16" : "/icon/16.png", @@ -28,7 +28,7 @@ "48" : "/icon/48.png", "128" : "/icon/128.png" }, - "options_page" : "settings.html", + "options_page" : "options.html", "content_scripts" : [ { "js" : ["snail.js"], diff --git a/extension-files/settings.html b/extension-files/options.html similarity index 100% rename from extension-files/settings.html rename to extension-files/options.html diff --git a/extension-files/popup.html b/extension-files/popup.html new file mode 100644 index 0000000..ea05228 --- /dev/null +++ b/extension-files/popup.html @@ -0,0 +1,118 @@ + + + + MySnail Settings + + + + + + + +

MySnail Settings

+ + + + + +
+
+

Snail Size

+ +
+
+
+

Snail Speed

+ +
+

+
+

Snail Colors

+ + + + + + + + + +

+ +

+
+ + + + + +
+
+ + From ee4efe307677f9851b09cde156961c5061688370 Mon Sep 17 00:00:00 2001 From: Wesley McGinn Date: Thu, 4 Apr 2024 15:36:03 -0400 Subject: [PATCH 02/63] Introduce snail to page immediately --- extension-files/snail.js | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/extension-files/snail.js b/extension-files/snail.js index 6e812e3..acb840e 100644 --- a/extension-files/snail.js +++ b/extension-files/snail.js @@ -113,16 +113,4 @@ class mySnail { } } -var snailList = []; -if (document.title == "MySnail Settings") { - snailList.push(new mySnail(true)); -} else { - var snailInterval = window.setInterval(function() { - if (document.readyState == 'complete') { - if (document.getElementsByClassName("mySnail").length == 0) { - snailList.push(new mySnail()); - } - window.clearInterval(snailInterval); - } - }, 500); -} +snail = new mySnail(); From a1a9e88186317cbea5073bc0db8569b57191f32a Mon Sep 17 00:00:00 2001 From: Wesley McGinn Date: Thu, 4 Apr 2024 15:44:07 -0400 Subject: [PATCH 03/63] Eliminate minor bug --- extension-files/settings.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extension-files/settings.js b/extension-files/settings.js index 89b6ae4..1cb7dd1 100644 --- a/extension-files/settings.js +++ b/extension-files/settings.js @@ -60,7 +60,7 @@ function updateStorage() { chrome.storage.sync.set({'bodyColorHigh' : document.getElementById("bodyColorHigh").value}); chrome.storage.sync.set({'snailSize' : document.getElementById("sizeAdjust").value}); chrome.storage.sync.set({'snailSpeed' : document.getElementById("snailSpeed").value}); - snailList[0].getInfoFromPopup(); + snail.getInfoFromPopup(); } function revert() { From 5d441193354ddc048d556c96d387a6ec8f841a94 Mon Sep 17 00:00:00 2001 From: Wesley McGinn Date: Sat, 6 Apr 2024 18:33:47 -0400 Subject: [PATCH 04/63] Freeze Snail on Settings Page --- extension-files/snail.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/extension-files/snail.js b/extension-files/snail.js index acb840e..e42c2c5 100644 --- a/extension-files/snail.js +++ b/extension-files/snail.js @@ -114,3 +114,6 @@ class mySnail { } snail = new mySnail(); +if (document.title == "MySnail Settings") { + snail.frozen = true; +} From 41fc64d8b1a1b44e7fa6c8527284f85d1a5d987f Mon Sep 17 00:00:00 2001 From: Wesley McGinn Date: Sat, 6 Apr 2024 18:34:36 -0400 Subject: [PATCH 05/63] Remove unneeded favicon The favicon is not needed for an extension popup as it will not be displayed anyways. --- extension-files/popup.html | 1 - 1 file changed, 1 deletion(-) diff --git a/extension-files/popup.html b/extension-files/popup.html index ea05228..b36574d 100644 --- a/extension-files/popup.html +++ b/extension-files/popup.html @@ -2,7 +2,6 @@ MySnail Settings - @@ -85,7 +136,14 @@

MySnail 2.0BETA Settings

- +
+ + +
+
diff --git a/extension-files/settings.js b/extension-files/settings.js index be29009..4d47f41 100644 --- a/extension-files/settings.js +++ b/extension-files/settings.js @@ -13,7 +13,7 @@ var snailJudgeTrained = false; var trainingData; document.addEventListener('DOMContentLoaded', function() { - chrome.storage.sync.get(['innerShellColor','shellColor','bodyColorLow','bodyColorHigh','snailSize','snailSpeed','ss_battery','ss_mysnail','ss_water','ss_screentime','ss_funfact','ss_news']).then((result) => { + chrome.storage.sync.get(['innerShellColor','shellColor','bodyColorLow','bodyColorHigh','snailSize','snailSpeed','ss_battery','ss_mysnail','ss_water','ss_screentime','ss_funfact','ss_news','showSnail']).then((result) => { if (result.innerShellColor == undefined) { revert(); } else { @@ -36,6 +36,9 @@ document.addEventListener('DOMContentLoaded', function() { document.getElementById('ss_funfact').checked = result.ss_funfact; document.getElementById('ss_news').checked = result.ss_news; } + if (document.getElementById("showSnail") != null) { + document.getElementById("showSnail").checked = result.showSnail; + } }); document.getElementById("sliders").addEventListener('click', updateStorage, false); document.getElementById("submit").addEventListener('click', updateStorage, false); @@ -55,6 +58,13 @@ document.addEventListener('DOMContentLoaded', function() { }); }, false); } + if (document.getElementById("showSnail") != null) { + document.getElementById("showSnail").addEventListener('input', function() { + setTimeout(function() { + chrome.storage.sync.set({'showSnail' : document.getElementById("showSnail").checked }); + }, 700); + }, false); + } document.getElementById("revert").addEventListener('click', revert, false); document.getElementById("randomize").addEventListener('click', function() { document.getElementById("randomize").disabled = "true"; diff --git a/extension-files/snail.js b/extension-files/snail.js index 84c98be..ce482bb 100644 --- a/extension-files/snail.js +++ b/extension-files/snail.js @@ -55,7 +55,7 @@ class mySnail { this.snail.children[0].children[1].children[0].children[1].children[1].attributes.fill.value = colorList[3]; } getInfoFromPopup() { - chrome.storage.sync.get(['innerShellColor','shellColor','bodyColorLow','bodyColorHigh','snailSize','snailSpeed']).then((result) => { + chrome.storage.sync.get(['innerShellColor','shellColor','bodyColorLow','bodyColorHigh','snailSize','snailSpeed','showSnail']).then((result) => { if (result.shellColor == undefined) { this.setColors(["#00f2ff", "#003fff", "#ffaa00", "#ffe500"]); } else { @@ -76,6 +76,11 @@ class mySnail { this.x = -700 * this.size; this.gotSizeInfo = true; } + if (result.showSnail == false) { + this.hide(); + } else { + this.show(); + } }); chrome.storage.sync.onChanged.addListener(() => { this.getInfoFromPopup(); From 43e4c2fa112dfef125d121225c9f9df5736adeac Mon Sep 17 00:00:00 2001 From: Wesley McGinn Date: Sun, 7 Apr 2024 22:19:46 -0400 Subject: [PATCH 45/63] Add button for more settings Opens options.html. --- extension-files/popup.html | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/extension-files/popup.html b/extension-files/popup.html index 2b02684..cf2571b 100644 --- a/extension-files/popup.html +++ b/extension-files/popup.html @@ -66,17 +66,22 @@ } .littleTable { width: 101.4%; + table-layout: fixed; } #submit { background-color: rgb(4, 172, 4); width: 95%; } - #revert { - background-color: rgb(220, 21, 21); - } #randomize { background-color: yellow; color: black; + width: 95%; + } + #revert { + background-color: rgb(220, 21, 21); + } + #more { + background-color: blue; } .onoff { position: relative; @@ -166,13 +171,14 @@

Snail Colors



- +

+

- +
From a68c3826fd623f31c7063a4fe82185c2748a4e73 Mon Sep 17 00:00:00 2001 From: Wesley McGinn Date: Fri, 12 Apr 2024 00:56:23 -0400 Subject: [PATCH 46/63] Create queue system & add battery warning queuing --- extension-files/snail.js | 43 ++++++++++++++++++++++++++++++---------- 1 file changed, 32 insertions(+), 11 deletions(-) diff --git a/extension-files/snail.js b/extension-files/snail.js index ce482bb..aaefe66 100644 --- a/extension-files/snail.js +++ b/extension-files/snail.js @@ -8,6 +8,7 @@ class mySnail { this.gotSizeInfo = false; this.speed = Speed; this.frozen = Freeze; + this.queuing = []; this.wordBubble = document.createElement("div"); this.wordBubble.style = "position:fixed;overflow:visible;padding:12px;background-color:white;border:solid black 2px;border-radius:21px;border-bottom-right-radius:0px;box-shadow:#000a -2px 5px 5px;font-family:'Arial Rounded MT Bold','Asap SemiBold','Rounded Mplus 1c Bold',FairyMuffinRoundPop,'Gill Sans','Trebuchet MS',sans-serif;font-size:12pt;width:270px;color:black;margin-bottom:0px;bottom:-5px;right:-1000px;display:none"; this.snail = document.createElement("div"); @@ -34,6 +35,11 @@ class mySnail { } this.snail.style.left = this.x.toString()+"px"; if (this.x > window.innerWidth || this.x < -700*this.size) { this.x = -700*this.size; } + if (this.queuing.length > 0) { + if (!document.hidden && snail.x > 270 && snail.x < 0.7*window.innerWidth && !this.showingBubble()) { + this.text(this.queuing.pop(), 7) + } + } }, 15); // 70fps } setSize(newSize) { @@ -101,6 +107,9 @@ class mySnail { showingBubble() { return !(this.wordBubble.style.display == "none"); } + getText() { + return this.wordBubble.innerHTML; + } text(words, durationSeconds = 0) { this.wordBubble.innerHTML = words; this.showBubble(); @@ -110,6 +119,9 @@ class mySnail { }, 1000*durationSeconds); } } + queue(message) { + this.queuing.push(message); + } } snail = new mySnail(); @@ -123,17 +135,26 @@ chrome.storage.sync.get(['ss_battery','ss_mysnail','ss_water','ss_screentime','s }); snailInterval = window.setInterval(function() { - if (!document.hidden && snail.x > 270 && snail.x < window.innerWidth * 0.7) { - if (whatSnailShouldSay.ss_battery) { - navigator.getBattery().then(function(battery) { - if (!battery.charging && battery.level <= 0.05) { - if (Math.random() > 0.5) { - snail.text("Your computer battery will die soon if you don't plug it in. You are at " + Math.round(100*battery.level).toString() + "% right now.", 7); - } else { - snail.text("Your computer battery is at " + Math.round(100*battery.level).toString() + "%. You may want to charge your computer soon.", 7); - } + navigator.getBattery().then(function(battery) { + battery.onlevelchange = () => { + if (whatSnailShouldSay.ss_battery && !battery.charging && battery.level <= 0.05) { + if (battery.level <= 0.01) { + snail.queue("YOUR COMPUTER BATTERY IS AT 1%!!!!! PLUG IN YOUR COMPUTER IMMEDIATELY!"); + } else if (Math.random() > 0.5) { + snail.queue("Plug in your computer soon! You are at " + Math.round(100*battery.level).toString() + "% right now.", 7); + } else { + snail.queue("Your computer battery is at " + Math.round(100*battery.level).toString() + "%. You may want to charge your computer soon.", 7); } - }); + } } - } + battery.onchargingchange = () => { + if (battery.charging) { + if (snail.getText().toLowerCase().indexOf("your computer") != -1) { + snail.hideBubble(); + } + } else if (battery.level <= 0.05) { + snail.queue("Your computer has come unplugged and is not currently charging, but the battery is at " + Math.round(100*battery.level).toString() + "%. You may want to plug your computer back in.", 7); + } + } + }); }, 30000); From 674edc493bec94ffbae23fc2553fc51b2ea763f9 Mon Sep 17 00:00:00 2001 From: Wesley McGinn Date: Sun, 14 Apr 2024 17:21:57 -0400 Subject: [PATCH 47/63] Making snail appear with JS will not ruin prints When the snail is made visible by javascript, it will still not be visible when you try to print the page you are on. --- extension-files/snail.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extension-files/snail.js b/extension-files/snail.js index aaefe66..4032f1a 100644 --- a/extension-files/snail.js +++ b/extension-files/snail.js @@ -1,5 +1,5 @@ var noprint = document.createElement("style"); -noprint.innerHTML = "@media print {.mySnail{display:none}}"; +noprint.innerHTML = "@media print {.mySnail{display:none !important}}"; document.head.appendChild(noprint); class mySnail { From d38bc21e4079d905ab7674f90aaa446364cc0501 Mon Sep 17 00:00:00 2001 From: Wesley McGinn Date: Sun, 14 Apr 2024 17:22:42 -0400 Subject: [PATCH 48/63] Add variable for reading speed --- extension-files/snail.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/extension-files/snail.js b/extension-files/snail.js index 4032f1a..dc8cbfb 100644 --- a/extension-files/snail.js +++ b/extension-files/snail.js @@ -9,6 +9,7 @@ class mySnail { this.speed = Speed; this.frozen = Freeze; this.queuing = []; + this.readingSpeed = 0.044; this.wordBubble = document.createElement("div"); this.wordBubble.style = "position:fixed;overflow:visible;padding:12px;background-color:white;border:solid black 2px;border-radius:21px;border-bottom-right-radius:0px;box-shadow:#000a -2px 5px 5px;font-family:'Arial Rounded MT Bold','Asap SemiBold','Rounded Mplus 1c Bold',FairyMuffinRoundPop,'Gill Sans','Trebuchet MS',sans-serif;font-size:12pt;width:270px;color:black;margin-bottom:0px;bottom:-5px;right:-1000px;display:none"; this.snail = document.createElement("div"); @@ -37,7 +38,8 @@ class mySnail { if (this.x > window.innerWidth || this.x < -700*this.size) { this.x = -700*this.size; } if (this.queuing.length > 0) { if (!document.hidden && snail.x > 270 && snail.x < 0.7*window.innerWidth && !this.showingBubble()) { - this.text(this.queuing.pop(), 7) + var snailMessage = this.queuing.pop(); + this.text(snailMessage, this.readingSpeed * snailMessage.length + 2); } } }, 15); // 70fps From 5cac1e3cd5f2932aca838f71fb2633e79c0ca844 Mon Sep 17 00:00:00 2001 From: Wesley McGinn Date: Sun, 14 Apr 2024 17:26:04 -0400 Subject: [PATCH 49/63] Do not let snail speak if it is invisible --- extension-files/snail.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/extension-files/snail.js b/extension-files/snail.js index dc8cbfb..a8ce248 100644 --- a/extension-files/snail.js +++ b/extension-files/snail.js @@ -37,7 +37,7 @@ class mySnail { this.snail.style.left = this.x.toString()+"px"; if (this.x > window.innerWidth || this.x < -700*this.size) { this.x = -700*this.size; } if (this.queuing.length > 0) { - if (!document.hidden && snail.x > 270 && snail.x < 0.7*window.innerWidth && !this.showingBubble()) { + if (!document.hidden && this.visible() && snail.x > 270 && snail.x < 0.7*window.innerWidth && !this.showingBubble()) { var snailMessage = this.queuing.pop(); this.text(snailMessage, this.readingSpeed * snailMessage.length + 2); } @@ -100,6 +100,9 @@ class mySnail { show() { this.snail.style.display = ''; } + visible() { + return !(this.snail.style.display == "none"); + } hideBubble() { this.wordBubble.style.display = "none"; } From 048918693c1677ccb8328212f941c6f7539ca6a6 Mon Sep 17 00:00:00 2001 From: Wesley McGinn Date: Sun, 14 Apr 2024 17:29:51 -0400 Subject: [PATCH 50/63] Click word bubble to close message --- extension-files/snail.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/extension-files/snail.js b/extension-files/snail.js index a8ce248..8ac6bae 100644 --- a/extension-files/snail.js +++ b/extension-files/snail.js @@ -11,7 +11,13 @@ class mySnail { this.queuing = []; this.readingSpeed = 0.044; this.wordBubble = document.createElement("div"); - this.wordBubble.style = "position:fixed;overflow:visible;padding:12px;background-color:white;border:solid black 2px;border-radius:21px;border-bottom-right-radius:0px;box-shadow:#000a -2px 5px 5px;font-family:'Arial Rounded MT Bold','Asap SemiBold','Rounded Mplus 1c Bold',FairyMuffinRoundPop,'Gill Sans','Trebuchet MS',sans-serif;font-size:12pt;width:270px;color:black;margin-bottom:0px;bottom:-5px;right:-1000px;display:none"; + this.wordBubble.style = "cursor:alias;position:fixed;overflow:visible;padding:12px;background-color:white;border:solid black 2px;border-radius:21px;border-bottom-right-radius:0px;box-shadow:#000a -2px 5px 5px;font-family:'Arial Rounded MT Bold','Asap SemiBold','Rounded Mplus 1c Bold',FairyMuffinRoundPop,'Gill Sans','Trebuchet MS',sans-serif;font-size:12pt;width:270px;color:black;margin-bottom:0px;bottom:-5px;right:-1000px;display:none"; + this.wordBubble.classList = ["mySnail"]; + this.wordBubble.title = "Click to close"; + this.wordBubble.onclick = () => { + window.clearTimeout(this.stopSpeaking); + this.hideBubble(); + } this.snail = document.createElement("div"); this.snail.innerHTML = ''; this.snail.style = 'position:fixed;margin-bottom:0px;bottom:-5px;left:-1000px;padding:0px;pointer-events:none;background:none'; @@ -119,7 +125,7 @@ class mySnail { this.wordBubble.innerHTML = words; this.showBubble(); if (durationSeconds != 0) { - setTimeout(() => { + this.stopSpeaking = window.setTimeout(() => { this.hideBubble(); }, 1000*durationSeconds); } From 15b046ed27461e7e7ee51326e6875c54cbef76af Mon Sep 17 00:00:00 2001 From: Wesley McGinn Date: Sun, 14 Apr 2024 17:30:27 -0400 Subject: [PATCH 51/63] Add important functions to use --- extension-files/snail.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/extension-files/snail.js b/extension-files/snail.js index 8ac6bae..3209ed7 100644 --- a/extension-files/snail.js +++ b/extension-files/snail.js @@ -135,6 +135,22 @@ class mySnail { } } +function todayID() { + var today = new Date(); + return (367*today.getFullYear() + 32*today.getMonth() + today.getDate()).toString(); +} + +async function getJSON(URL) { + const req = new Request(URL); + req.cache = "no-store"; + try { + const res = (await fetch(req)).json(); + return res; + } catch(err) { + return {"error" : err}; + } +} + snail = new mySnail(); chrome.storage.sync.get(['ss_battery','ss_mysnail','ss_water','ss_screentime','ss_funfact','ss_news']).then((result) => { From 6484156453abaf17a2a2f597059da06d07b1a2e7 Mon Sep 17 00:00:00 2001 From: Wesley McGinn Date: Sun, 14 Apr 2024 17:31:24 -0400 Subject: [PATCH 52/63] New sync variables to track fun fact and news These will be used to prevent the snails from stating the same fun fact or breaking news multiple times in one day. --- extension-files/snail.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extension-files/snail.js b/extension-files/snail.js index 3209ed7..298631b 100644 --- a/extension-files/snail.js +++ b/extension-files/snail.js @@ -153,7 +153,7 @@ async function getJSON(URL) { snail = new mySnail(); -chrome.storage.sync.get(['ss_battery','ss_mysnail','ss_water','ss_screentime','ss_funfact','ss_news']).then((result) => { +chrome.storage.sync.get(['ss_battery','ss_mysnail','ss_water','ss_screentime','ss_funfact','ss_news','snail_lastFunfact','snail_lastNews']).then((result) => { whatSnailShouldSay = result; if (whatSnailShouldSay.ss_news == undefined) { whatSnailShouldSay = {'ss_battery' : true, 'ss_mysnail' : true, 'ss_water' : true, 'ss_screentime' : true, 'ss_funfact' : true, 'ss_news' : true}; From 03197e1f6dd7b9d1f0fd9ce65cbbe3fed42b310f Mon Sep 17 00:00:00 2001 From: Wesley McGinn Date: Sun, 14 Apr 2024 17:31:54 -0400 Subject: [PATCH 53/63] Use event listener for page load actions --- extension-files/snail.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/extension-files/snail.js b/extension-files/snail.js index 298631b..7c70259 100644 --- a/extension-files/snail.js +++ b/extension-files/snail.js @@ -161,7 +161,7 @@ chrome.storage.sync.get(['ss_battery','ss_mysnail','ss_water','ss_screentime','s } }); -snailInterval = window.setInterval(function() { +window.addEventListener("load", () => { navigator.getBattery().then(function(battery) { battery.onlevelchange = () => { if (whatSnailShouldSay.ss_battery && !battery.charging && battery.level <= 0.05) { @@ -184,4 +184,4 @@ snailInterval = window.setInterval(function() { } } }); -}, 30000); +}); From f59e466288a19054df8f75d1060c1046b9da19a6 Mon Sep 17 00:00:00 2001 From: Wesley McGinn Date: Sun, 14 Apr 2024 18:19:17 -0400 Subject: [PATCH 54/63] Add snail speech for daily fun facts --- extension-files/snail.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/extension-files/snail.js b/extension-files/snail.js index 7c70259..534ac57 100644 --- a/extension-files/snail.js +++ b/extension-files/snail.js @@ -184,4 +184,23 @@ window.addEventListener("load", () => { } } }); + if (whatSnailShouldSay.ss_funfact || whatSnailShouldSay.ss_news) { + getJSON("https://sheets.googleapis.com/v4/spreadsheets/1dg2Js_kdY-Y-EAkjrBOrHJosHM8yPHLN1oZB5a9SXXk/values/by_date!C2:E?key=AIzaSyAQnxcD0daH7TggZSWS_RyvTBE6y2FakZE&majorDimension=COLUMNS").then(function(x) { + if (x.error == undefined) { + if (x.values[0].indexOf(todayID()) != -1) { + if (whatSnailShouldSay.ss_funfact && whatSnailShouldSay.snail_lastFunfact != todayID()) { + snail.queue(x.values[1][x.values[0].indexOf(todayID())]); + snailFunfactWait = window.setInterval(function() { + if (snail.queuing.length == 0) { + chrome.storage.sync.set({'snail_lastFunfact' : todayID()}); + window.clearInterval(snailFunfactWait); + } + }, 2000); + } + } else { + console.error("A fun fact has not been posted to the snail's system for today. Please contact email.technologysnail@gmail.com immediately to let us know."); + } + } + }); + } }); From 5b13b87cc4ea3d0505d7aa971023782f270c66ab Mon Sep 17 00:00:00 2001 From: Wesley McGinn Date: Sun, 14 Apr 2024 18:19:47 -0400 Subject: [PATCH 55/63] Add snail speech for breaking news --- extension-files/snail.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/extension-files/snail.js b/extension-files/snail.js index 534ac57..e07eb04 100644 --- a/extension-files/snail.js +++ b/extension-files/snail.js @@ -197,6 +197,15 @@ window.addEventListener("load", () => { } }, 2000); } + if (whatSnailShouldSay.ss_news && whatSnailShouldSay.snail_lastNews != todayID() && parseInt(Date.call().slice(16,18)) >= 12 && x.values[2][x.values[0].indexOf(todayID())]) { + snail.queue(x.values[2][x.values[0].indexOf(todayID())]); + snailNewsWait = window.setInterval(function() { + if (snail.queuing.length == 0) { + chrome.storage.sync.set({'snail_lastNews' : todayID()}); + window.clearInterval(snailNewsWait); + } + }, 2000); + } } else { console.error("A fun fact has not been posted to the snail's system for today. Please contact email.technologysnail@gmail.com immediately to let us know."); } From ef565a894165f8d1ddb5c6300d83cea580703a63 Mon Sep 17 00:00:00 2001 From: Wesley McGinn Date: Mon, 15 Apr 2024 14:38:52 -0400 Subject: [PATCH 56/63] Enhance error prevention Battery level 0% indicates Chrome battery-detection error. --- extension-files/snail.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/extension-files/snail.js b/extension-files/snail.js index e07eb04..362eaaa 100644 --- a/extension-files/snail.js +++ b/extension-files/snail.js @@ -164,9 +164,9 @@ chrome.storage.sync.get(['ss_battery','ss_mysnail','ss_water','ss_screentime','s window.addEventListener("load", () => { navigator.getBattery().then(function(battery) { battery.onlevelchange = () => { - if (whatSnailShouldSay.ss_battery && !battery.charging && battery.level <= 0.05) { + if (whatSnailShouldSay.ss_battery && !battery.charging && battery.level <= 0.05 && battery.level > 0) { if (battery.level <= 0.01) { - snail.queue("YOUR COMPUTER BATTERY IS AT 1%!!!!! PLUG IN YOUR COMPUTER IMMEDIATELY!"); + snail.queue("YOUR COMPUTER BATTERY IS AT 1%! PLUG IN YOUR COMPUTER IMMEDIATELY!"); } else if (Math.random() > 0.5) { snail.queue("Plug in your computer soon! You are at " + Math.round(100*battery.level).toString() + "% right now.", 7); } else { From 4e84e480821e8b8d0bff4e18cda8fa9ffbb6eba6 Mon Sep 17 00:00:00 2001 From: Wesley McGinn Date: Mon, 15 Apr 2024 14:39:37 -0400 Subject: [PATCH 57/63] Notify user when they unplug on less than 10% pwr --- extension-files/snail.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extension-files/snail.js b/extension-files/snail.js index 362eaaa..15a5863 100644 --- a/extension-files/snail.js +++ b/extension-files/snail.js @@ -179,7 +179,7 @@ window.addEventListener("load", () => { if (snail.getText().toLowerCase().indexOf("your computer") != -1) { snail.hideBubble(); } - } else if (battery.level <= 0.05) { + } else if (battery.level <= 0.1) { snail.queue("Your computer has come unplugged and is not currently charging, but the battery is at " + Math.round(100*battery.level).toString() + "%. You may want to plug your computer back in.", 7); } } From 336a968de10986fc68d613d6008059a34e55a88f Mon Sep 17 00:00:00 2001 From: Wesley McGinn Date: Wed, 17 Apr 2024 00:17:58 -0400 Subject: [PATCH 58/63] FIX BUG: Save settings when slider at endpoint Previously, when the slider for setting the snail's size or speed was dragged to other endpoint but the mouse button was released while the mouse was not on the slider, the new setting would not save. Now, when previewing a maximum/minimum size or speed, as soon as the slider hits the end the setting will be saved to Chrome sync. --- extension-files/settings.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/extension-files/settings.js b/extension-files/settings.js index 4d47f41..e593929 100644 --- a/extension-files/settings.js +++ b/extension-files/settings.js @@ -45,6 +45,14 @@ document.addEventListener('DOMContentLoaded', function() { document.getElementById("sliders").addEventListener('input', function() { snail.setSize(document.getElementById("sizeAdjust").value/100); snail.speed = document.getElementById("snailSpeed").value/100; + if ( + document.getElementById("sizeAdjust").value == document.getElementById("sizeAdjust").min || + document.getElementById("sizeAdjust").value == document.getElementById("sizeAdjust").max || + document.getElementById("snailSpeed").value == document.getElementById("snailSpeed").min || + document.getElementById("snailSpeed").value == document.getElementById("snailSpeed").max + ) { + updateStorage(); + } }, false); if (document.getElementById("speech") != null) { document.getElementById("speech").addEventListener('input', function() { From 1eaee041308db7c865615e492510dfadf0ffa4cf Mon Sep 17 00:00:00 2001 From: Wesley McGinn Date: Wed, 17 Apr 2024 00:18:41 -0400 Subject: [PATCH 59/63] Notification to update MySnail when outdated --- extension-files/snail.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/extension-files/snail.js b/extension-files/snail.js index 15a5863..bec2786 100644 --- a/extension-files/snail.js +++ b/extension-files/snail.js @@ -1,3 +1,5 @@ +var mySnail_version = "2.0.0"; + var noprint = document.createElement("style"); noprint.innerHTML = "@media print {.mySnail{display:none !important}}"; document.head.appendChild(noprint); @@ -151,7 +153,7 @@ async function getJSON(URL) { } } -snail = new mySnail(); +const snail = new mySnail(); chrome.storage.sync.get(['ss_battery','ss_mysnail','ss_water','ss_screentime','ss_funfact','ss_news','snail_lastFunfact','snail_lastNews']).then((result) => { whatSnailShouldSay = result; @@ -212,4 +214,13 @@ window.addEventListener("load", () => { } }); } + if (whatSnailShouldSay.ss_mysnail) { + getJSON("https://sheets.googleapis.com/v4/spreadsheets/1dg2Js_kdY-Y-EAkjrBOrHJosHM8yPHLN1oZB5a9SXXk/values/live!B:D?key=AIzaSyAQnxcD0daH7TggZSWS_RyvTBE6y2FakZE&majorDimension=ROWS").then(function(x) { + if (x.error == undefined) { + if (x.values[0][0] != mySnail_version && x.values[0][1] == "TRUE") { + snail.queue(x.values[0][2]); + } + } + }); + } }); From 27ad96fa55963b01ed4bfcf800ccf805ef9bb6ce Mon Sep 17 00:00:00 2001 From: Wesley McGinn Date: Fri, 26 Apr 2024 15:13:03 -0400 Subject: [PATCH 60/63] Majorly reduce memory usage A function with a shorter name (`$`) replaced a very common function with a longer name (`document.getElementById`). --- extension-files/settings.js | 128 +++++++++++++++++++----------------- 1 file changed, 66 insertions(+), 62 deletions(-) diff --git a/extension-files/settings.js b/extension-files/settings.js index e593929..5c12640 100644 --- a/extension-files/settings.js +++ b/extension-files/settings.js @@ -8,6 +8,10 @@ async function getJSON(URL) { } } +function $(elementID) { + return document.getElementById(elementID); +} + const snailJudge = new brain.NeuralNetwork(); var snailJudgeTrained = false; var trainingData; @@ -18,64 +22,64 @@ document.addEventListener('DOMContentLoaded', function() { revert(); } else { document.body.style.backgroundColor = (result.innerShellColor); - document.getElementById('innerShellColor').value = result.innerShellColor; - document.getElementById('shellColor').value = result.shellColor; - document.getElementById('bodyColorLow').value = result.bodyColorLow; - document.getElementById('bodyColorHigh').value = result.bodyColorHigh; - document.getElementById('sizeAdjust').value = parseInt(result.snailSize); - document.getElementById('sizeAdjust').value = parseInt(result.snailSize); - document.getElementById('snailSpeed').value = parseInt(result.snailSpeed); + $('innerShellColor').value = result.innerShellColor; + $('shellColor').value = result.shellColor; + $('bodyColorLow').value = result.bodyColorLow; + $('bodyColorHigh').value = result.bodyColorHigh; + $('sizeAdjust').value = parseInt(result.snailSize); + $('sizeAdjust').value = parseInt(result.snailSize); + $('snailSpeed').value = parseInt(result.snailSpeed); } if (result.ss_news == undefined) { chrome.storage.sync.set({'ss_battery' : true, 'ss_mysnail' : true, 'ss_water' : true, 'ss_screentime' : true, 'ss_funfact' : true, 'ss_news' : true}); - } else if (document.getElementById("speech") != null) { - document.getElementById('ss_battery').checked = result.ss_battery; - document.getElementById('ss_mysnail').checked = result.ss_mysnail; - document.getElementById('ss_water').checked = result.ss_water; - document.getElementById('ss_screentime').checked = result.ss_screentime; - document.getElementById('ss_funfact').checked = result.ss_funfact; - document.getElementById('ss_news').checked = result.ss_news; + } else if ($("speech") != null) { + $('ss_battery').checked = result.ss_battery; + $('ss_mysnail').checked = result.ss_mysnail; + $('ss_water').checked = result.ss_water; + $('ss_screentime').checked = result.ss_screentime; + $('ss_funfact').checked = result.ss_funfact; + $('ss_news').checked = result.ss_news; } - if (document.getElementById("showSnail") != null) { - document.getElementById("showSnail").checked = result.showSnail; + if ($("showSnail") != null) { + $("showSnail").checked = result.showSnail; } }); - document.getElementById("sliders").addEventListener('click', updateStorage, false); - document.getElementById("submit").addEventListener('click', updateStorage, false); - document.getElementById("sliders").addEventListener('input', function() { - snail.setSize(document.getElementById("sizeAdjust").value/100); - snail.speed = document.getElementById("snailSpeed").value/100; + $("sliders").addEventListener('click', updateStorage, false); + $("submit").addEventListener('click', updateStorage, false); + $("sliders").addEventListener('input', function() { + snail.setSize($("sizeAdjust").value/100); + snail.speed = $("snailSpeed").value/100; if ( - document.getElementById("sizeAdjust").value == document.getElementById("sizeAdjust").min || - document.getElementById("sizeAdjust").value == document.getElementById("sizeAdjust").max || - document.getElementById("snailSpeed").value == document.getElementById("snailSpeed").min || - document.getElementById("snailSpeed").value == document.getElementById("snailSpeed").max + $("sizeAdjust").value == $("sizeAdjust").min || + $("sizeAdjust").value == $("sizeAdjust").max || + $("snailSpeed").value == $("snailSpeed").min || + $("snailSpeed").value == $("snailSpeed").max ) { updateStorage(); } }, false); - if (document.getElementById("speech") != null) { - document.getElementById("speech").addEventListener('input', function() { + if ($("speech") != null) { + $("speech").addEventListener('input', function() { chrome.storage.sync.set({ - 'ss_battery' : document.getElementById('ss_battery').checked, - 'ss_mysnail' : document.getElementById('ss_mysnail').checked, - 'ss_water' : document.getElementById('ss_water').checked, - 'ss_screentime' : document.getElementById('ss_screentime').checked, - 'ss_funfact' : document.getElementById('ss_funfact').checked, - 'ss_news' : document.getElementById('ss_news').checked + 'ss_battery' : $('ss_battery').checked, + 'ss_mysnail' : $('ss_mysnail').checked, + 'ss_water' : $('ss_water').checked, + 'ss_screentime' : $('ss_screentime').checked, + 'ss_funfact' : $('ss_funfact').checked, + 'ss_news' : $('ss_news').checked }); }, false); } - if (document.getElementById("showSnail") != null) { - document.getElementById("showSnail").addEventListener('input', function() { + if ($("showSnail") != null) { + $("showSnail").addEventListener('input', function() { setTimeout(function() { - chrome.storage.sync.set({'showSnail' : document.getElementById("showSnail").checked }); + chrome.storage.sync.set({'showSnail' : $("showSnail").checked }); }, 700); }, false); } - document.getElementById("revert").addEventListener('click', revert, false); - document.getElementById("randomize").addEventListener('click', function() { - document.getElementById("randomize").disabled = "true"; + $("revert").addEventListener('click', revert, false); + $("randomize").addEventListener('click', function() { + $("randomize").disabled = "true"; document.documentElement.style.cursor = "progress"; if (!snailJudgeTrained) { getJSON("https://technology-snail.github.io/MySnail/resources/ai_snail_training_data.json").then(function(x) { @@ -85,15 +89,15 @@ document.addEventListener('DOMContentLoaded', function() { snailJudge.train(trainingData); snailJudgeTrained = true; randomize(); - document.getElementById("randomize").disabled = ''; + $("randomize").disabled = ''; document.documentElement.style.cursor = "default"; }, 500); } else { if (confirm("ERROR!\n\nSomething went wrong while fetching the snail judge's training data. The snail judge is an AI that is meant to determine what color combinations go well together, and it is necessary for nicely randomizing the colors on your snail.\n\nWould you like to randomize without the AI this time? (Color combo may be terrible, but you can always change it.)")) { - document.getElementById("innerShellColor").value = generateColor(); - document.getElementById("shellColor").value = generateColor(); - document.getElementById("bodyColorLow").value = generateColor(); - document.getElementById("bodyColorHigh").value = generateColor(); + $("innerShellColor").value = generateColor(); + $("shellColor").value = generateColor(); + $("bodyColorLow").value = generateColor(); + $("bodyColorHigh").value = generateColor(); updateStorage(); } } @@ -101,7 +105,7 @@ document.addEventListener('DOMContentLoaded', function() { } else { setTimeout(function() { randomize(); - document.getElementById("randomize").disabled = ''; + $("randomize").disabled = ''; document.documentElement.style.cursor = "default"; }, 500); } @@ -109,26 +113,26 @@ document.addEventListener('DOMContentLoaded', function() { },false); function updateStorage() { - document.body.style.backgroundColor = document.getElementById("innerShellColor").value; + document.body.style.backgroundColor = $("innerShellColor").value; chrome.storage.sync.set({ - 'innerShellColor' : document.getElementById("innerShellColor").value, - 'shellColor' : document.getElementById("shellColor").value, - 'bodyColorLow' : document.getElementById("bodyColorLow").value, - 'bodyColorHigh' : document.getElementById("bodyColorHigh").value, - 'snailSize' : document.getElementById("sizeAdjust").value, - 'snailSpeed' : document.getElementById("snailSpeed").value + 'innerShellColor' : $("innerShellColor").value, + 'shellColor' : $("shellColor").value, + 'bodyColorLow' : $("bodyColorLow").value, + 'bodyColorHigh' : $("bodyColorHigh").value, + 'snailSize' : $("sizeAdjust").value, + 'snailSpeed' : $("snailSpeed").value }); snail.getInfoFromPopup(); } function revert() { if (confirm("Are you sure you want to revert your snail to default? The snail's colors, size, and speed will all be changed to their default values.")) { - document.getElementById("innerShellColor").value = "#00f2ff"; - document.getElementById("shellColor").value = "#003fff"; - document.getElementById("bodyColorLow").value = "#ffaa00"; - document.getElementById("bodyColorHigh").value = "#ffe500"; - document.getElementById("sizeAdjust").value = "25"; - document.getElementById("snailSpeed").value = "20"; + $("innerShellColor").value = "#00f2ff"; + $("shellColor").value = "#003fff"; + $("bodyColorLow").value = "#ffaa00"; + $("bodyColorHigh").value = "#ffe500"; + $("sizeAdjust").value = "25"; + $("snailSpeed").value = "20"; updateStorage(); } } @@ -158,9 +162,9 @@ function randomize() { break; } } - document.getElementById("innerShellColor").value = c1; - document.getElementById("shellColor").value = c2; - document.getElementById("bodyColorLow").value = c3; - document.getElementById("bodyColorHigh").value = c4; + $("innerShellColor").value = c1; + $("shellColor").value = c2; + $("bodyColorLow").value = c3; + $("bodyColorHigh").value = c4; updateStorage(); } From d3b9a7436d3cce018f471f43b213aca296924685 Mon Sep 17 00:00:00 2001 From: Wesley McGinn Date: Fri, 26 Apr 2024 15:13:49 -0400 Subject: [PATCH 61/63] Convert error to warning --- extension-files/snail.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extension-files/snail.js b/extension-files/snail.js index bec2786..70d5f89 100644 --- a/extension-files/snail.js +++ b/extension-files/snail.js @@ -209,7 +209,7 @@ window.addEventListener("load", () => { }, 2000); } } else { - console.error("A fun fact has not been posted to the snail's system for today. Please contact email.technologysnail@gmail.com immediately to let us know."); + console.warn("A fun fact has not been posted to the snail's system for today. Please contact email.technologysnail@gmail.com immediately to let us know."); } } }); From d8d94dd7c7bad25c327f76b351c6c69859d89aca Mon Sep 17 00:00:00 2001 From: Wesley McGinn Date: Fri, 26 Apr 2024 15:15:27 -0400 Subject: [PATCH 62/63] Don't hide snail message until clicked This situation will be dealt with later. --- extension-files/snail.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extension-files/snail.js b/extension-files/snail.js index 70d5f89..20d1001 100644 --- a/extension-files/snail.js +++ b/extension-files/snail.js @@ -47,7 +47,7 @@ class mySnail { if (this.queuing.length > 0) { if (!document.hidden && this.visible() && snail.x > 270 && snail.x < 0.7*window.innerWidth && !this.showingBubble()) { var snailMessage = this.queuing.pop(); - this.text(snailMessage, this.readingSpeed * snailMessage.length + 2); + this.text(snailMessage); } } }, 15); // 70fps From 065fdc667b199fe4e1b510deab98b0daec538086 Mon Sep 17 00:00:00 2001 From: Wesley Date: Thu, 30 Jan 2025 00:12:45 -0500 Subject: [PATCH 63/63] Minor edit --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 37824f8..19f14f7 100644 --- a/README.md +++ b/README.md @@ -53,7 +53,7 @@ Version 2.0 of the chrome extension will bring drastic changes to MySnail, inclu - An options page for more settings beyond the usual found in the popup - A way to submit feedback to TechnologySnail (the business that develops MySnail) - Checkboxes in the options page to choose what the snail can talk about, including the following options: - - [x] Low Battery Notification at (customizable value, default = 5)% + - [x] Low Battery Notification at (customizable value, default = 5%) - [x] Notification when newer version of MySnail Chrome extension is available - [x] A reminder to drink water, randomly but at approximately 30 minute intervals - [x] Friendly reminder to get off screen at certain time, settable between 7:00pm and 11:00pm, defaulting to 10:00pm. (You can ignore this for five minutes, but the snail will tell you the same thing more sternly five minutes later, and five minutes after that the snail will make random elements from your screen start dissappearing... Back to normal at 4:00am.)