]> khamidou — GitHub mirrors - infinity-pools.git/commitdiff
Plugin works!
authorKarim Hamidou <khamidou@gmail.com>
Sat, 29 May 2021 23:40:16 +0000 (16:40 -0700)
committerKarim Hamidou <khamidou@gmail.com>
Sat, 29 May 2021 23:40:16 +0000 (16:40 -0700)
balloons.js [new file with mode: 0644]
frame.html [new file with mode: 0644]
index.html [deleted file]
manifest.json
start.js

diff --git a/balloons.js b/balloons.js
new file mode 100644 (file)
index 0000000..bba978e
--- /dev/null
@@ -0,0 +1,66 @@
+var windowWidth = window.innerWidth;
+var windowHeight = window.innerHeight;
+
+function pickANumber(max, min) {
+  return Math.random() * (max - min + min) + min;
+}
+
+function changeColors(el) {
+  el.removeClass();
+  var random = Math.floor(pickANumber(5,1));
+  el.addClass('bln-'+random+'-clone');
+}
+
+function resetBalloon(el) {
+  changeColors(el);
+
+  var scale = (pickANumber(0.9,0.5)).toFixed(1);
+  el.css('transform', 'scale(' + scale + ')');
+
+  var x = Math.floor(Math.random() * windowWidth);
+  el.css('left', x);
+  var y = Math.floor(Math.random() * 300 + windowHeight);
+  el.css('top', y);
+  releaseBalloon(el);
+}
+
+function releaseBalloon(el) {
+  var maxbllnSpeed = Math.floor(Math.random() * 20000 + 3000);
+  var wind = Math.floor(Math.random() * + 50);
+  var rotate = Math.floor(Math.random() * 860) + 100;
+
+  el.animate({top: '-150px', left: '+=' + wind + 0}, {
+  step: function() {
+    el.css({
+    transform: 'rotate('+rotate+'deg)',
+    transition: 'transform '+ maxbllnSpeed * .001  +'s linear'
+    });
+  },
+  duration: maxbllnSpeed,
+  easing: 'linear',
+  complete: function() {
+    resetBalloon(el);
+  }
+  });
+}
+
+function blowUpBalloons() {
+  for (i = 0; i < 100; i++) {
+  var el = $('.bln-1').clone();
+  el[0].style.display = 'block';
+  el.appendTo('.blns');
+
+  resetBalloon(el);
+
+  var position = el.position();
+
+  if (position.top > windowHeight || position.left > windowWidth || position.left < -100) {
+    resetBalloon(el);
+  }
+  }
+}
+
+$(document).ready(function() {
+  blowUpBalloons();
+})
+
diff --git a/frame.html b/frame.html
new file mode 100644 (file)
index 0000000..c6445b6
--- /dev/null
@@ -0,0 +1,21 @@
+<!doctype html5>
+<html>
+    <head>
+        <meta charset="UTF-8">
+        <link rel="stylesheet" href="style.css">
+    </head>
+    <body>
+        <div class="modal">
+            <!--     <span class="emoji">👏</span> -->
+            <span class="emoji round">🏆</span>
+            <h1>Congratulations!</h1>
+            <p>You've made it to the end of Twitter.</p>
+        </div>
+        <div class="blns">
+            <div class="bln-1" style="display: none"></div>
+        </div>
+        <script type="text/javascript" src="jquery.min.js"></script>
+        <script type="text/javascript" src="jquery-ui.min.js"></script>
+        <script type="text/javascript" src="balloons.js"></script>
+    </body>
+</html>
diff --git a/index.html b/index.html
deleted file mode 100644 (file)
index ed7664d..0000000
+++ /dev/null
@@ -1,85 +0,0 @@
-<!doctype html5>
-<html>
-    <head>
-        <link rel="stylesheet" href="style.css">
-    </head>
-    <body>
-        <div class="modal">
-            <!--     <span class="emoji">👏</span> -->
-            <span class="emoji round">🏆</span>
-            <h1>Congratulations!</h1>
-            <p>You've made it to the end of Twitter.</p>
-            <a href="#" class="modal-btn">Close window.</a>
-        </div>
-        <div class="blns">
-            <div class="bln-1" style="display: none"></div>
-        </div>
-        <script type="text/javascript" src="jquery.min.js"></script>
-        <script type="text/javascript" src="jquery-ui.min.js"></script>
-        <script type="text/javascript">
-        var windowWidth = window.innerWidth;
-               var windowHeight = window.innerHeight;
-
-               function pickANumber(max, min) {
-                 return Math.random() * (max - min + min) + min;
-               }
-
-               function changeColors(el) {
-                 el.removeClass();
-                 var random = Math.floor(pickANumber(5,1));
-                 el.addClass('bln-'+random+'-clone');
-               }
-
-               function resetBalloon(el) {
-                 changeColors(el);
-
-                 var scale = (pickANumber(0.9,0.5)).toFixed(1);
-                 el.css('transform', 'scale(' + scale + ')');
-
-                 var x = Math.floor(Math.random() * windowWidth);
-                 el.css('left', x);
-                 var y = Math.floor(Math.random() * 300 + windowHeight);
-                 el.css('top', y);
-                 releaseBalloon(el);
-               }
-
-               function releaseBalloon(el) {
-                 var maxbllnSpeed = Math.floor(Math.random() * 20000 + 3000);
-                 var wind = Math.floor(Math.random() * + 50);
-                 var rotate = Math.floor(Math.random() * 860) + 100;
-
-                 el.animate({top: '-150px', left: '+=' + wind + 0}, {
-                       step: function() {
-                         el.css({
-                               transform: 'rotate('+rotate+'deg)',
-                               transition: 'transform '+ maxbllnSpeed * .001  +'s linear'
-                         });
-                       },
-                       duration: maxbllnSpeed,
-                       easing: 'linear',
-                       complete: function() {
-                         resetBalloon(el);
-                       }
-                 });
-               }
-
-               function blowUpBalloons() {
-                 for (i = 0; i < 100; i++) {
-                       var el = $('.bln-1').clone();
-            el[0].style.display = 'block';
-                       el.appendTo('.blns');
-
-                       resetBalloon(el);
-
-                       var position = el.position();
-
-                       if (position.top > windowHeight || position.left > windowWidth || position.left < -100) {
-                         resetBalloon(el);
-                       }
-                 }
-               }
-
-               $(document).ready(function() { blowUpBalloons(); })
-        </script>
-    </body>
-</html>
index f17bb8f383cf8efe34f4a43599f0edef6833e7d3..24c85c391846185d32b7d407486c7434f6c4b086 100644 (file)
@@ -6,6 +6,9 @@
   "description": "An extension to hide Twitter's feed after 30 mins every day.",
   "update_url": "https://khamidou.com/extensions/update.xml",
   "permissions": ["storage"],
+  "web_accessible_resources": [
+    "frame.html"
+  ],
   "content_scripts": [
     {
       "matches": ["*://*.twitter.com/*"],
index a5ddbdc12c9cc0bce646b5d9d190a084d2a60e25..717b7184e0a462b6a45d199ec057b59826252e25 100644 (file)
--- a/start.js
+++ b/start.js
@@ -33,7 +33,7 @@ var refreshConfig = async function() {
 
   let data = await p;
 
-  let defaultConfig = {currentDay: getFormattedDate(), remainingMinutes: 15}
+  let defaultConfig = {currentDay: getFormattedDate(), remainingMinutes: 30}
   if (data.config == {} || data.config == undefined) {
     Object.assign(config, data.config);
     return;
@@ -43,7 +43,7 @@ var refreshConfig = async function() {
     // if this is a new day, reset the config.
     Object.assign(config, defaultConfig);
     return;
-  else {
+  } else {
     Object.assign(config, data.config);
     return;
   }
@@ -98,7 +98,15 @@ async function mainEventHandler() {
   await refreshConfig();
   console.log(config.remainingMinutes);
   if (config.remainingMinutes <= 0) {
-    alert("you're at time!");
+    // Avoid recursive frame insertion...
+    var extensionOrigin = 'chrome-extension://' + chrome.runtime.id;
+    if (!location.ancestorOrigins.contains(extensionOrigin)) {
+      var iframe = document.createElement('iframe');
+      // Must be declared at web_accessible_resources in manifest.json
+      iframe.src = chrome.runtime.getURL('frame.html');
+      window.location.href = iframe.src;
+    }
+
     return;
   }