Browse Source

Added files

Stephen Downward 2 years ago
parent
commit
3ddbf9b757
5 changed files with 84 additions and 1 deletions
  1. 11 1
      README.md
  2. BIN
      chrome-engine-packed.crx
  3. BIN
      icon.png
  4. 54 0
      main.js
  5. 19 0
      manifest.json

+ 11 - 1
README.md

@ -1,3 +1,13 @@
1 1
# jerkface-chrome
2 2
3
This is a chrome extension I wrote to prank some friends. Every day, it lowers playback rate on YouTube by 1%, until it hits a target speed of 70% - 30 days later.  It has the Chrome icon and calls itself "Chrome Engine" as a disguise.
3
This is a chrome extension I wrote to prank some friends. Every day, it lowers playback rate on YouTube by 1%, until it hits a target speed of 70% - 30 days later.  It has the Chrome icon and calls itself "Chrome Engine" as a disguise.
4
5
Speed controls still work as intended. There's also some slightly fancy mechanics under the hood - Check out the comments in the source code!
6
7
## To install:
8
9
1. Download "chrome-engine-packed.crx" from this repository
10
11
2. Navigate to chrome://extensions/
12
13
3. Drag and drop the downloaded file there, it will install

BIN
chrome-engine-packed.crx


BIN
icon.png


+ 54 - 0
main.js

@ -0,0 +1,54 @@
1
var videoElement = document.getElementsByClassName('video-stream')[0];
2
3
var speedModifier = 1.0;
4
var disableRateChangeEventListener = false; //Prevents event listener from triggering itself
5
6
//Using Chrome sync storage.
7
//The speed difference will be there on
8
//all of their devices, as long as they're signed in
9
//and using Chrome.
10
chrome.storage.sync.get(["lastRateChange"], function(items) {
11
    if(items.lastRateChange == null) {
12
        var now = new Date();
13
        now.setHours(24, 0, 0, 0);
14
        var rateChangeObj = {
15
            "timestamp": +now,
16
            "value": 1.00 //Gives a day of buffer time
17
        };
18
        chrome.storage.sync.set({"lastRateChange": rateChangeObj});
19
    }
20
    else {
21
        speedModifier = items.lastRateChange.value;
22
        //Speed loses 0.01, even if multiple days have passed.
23
        //If the user goes on vacation or doesn't visit YouTube for a few days,
24
        //they won't lose a few percent speed, which could be noticeable.
25
        if(speedModifier > 0.7 && new Date() > new Date(items.lastRateChange.timestamp)) { //It's the next day at minimum
26
            speedModifier -= 0.01;
27
            var now = new Date();
28
            now.setHours(24, 0, 0, 0);
29
            var rateChangeObj = {
30
                "timestamp": +now,
31
                "value": speedModifier
32
            };
33
            chrome.storage.sync.set({"lastRateChange": rateChangeObj});
34
        }
35
        disableRateChangeEventListener = true;
36
        videoElement.playbackRate *= speedModifier;
37
    }
38
});
39
40
videoElement.addEventListener('ratechange', function() { //Ensures speed controls still work
41
    if(!disableRateChangeEventListener) {
42
        disableRateChangeEventListener = true;
43
        var hasSound = videoElement.playbackRate >= 0.5;
44
        videoElement.playbackRate *= speedModifier;
45
        //Sound playback doesn't work if the video is playing slower than half speed.
46
        //This could raise some alarms if sound stops even when the user selects 0.5x speed.
47
        //So, if sound should be enabled, this adds a hard cap of 0.5x.
48
        //If the user selects 0.25, there's no sound anyway, so there's no reason to
49
        //enable this cap.
50
        if(hasSound && videoElement.playbackRate < 0.5) videoElement.playbackRate = 0.5;
51
    } else {
52
        disableRateChangeEventListener = false;
53
    }
54
});

+ 19 - 0
manifest.json

@ -0,0 +1,19 @@
1
{
2
    "manifest_version": 2,
3
4
    "name": "Chrome Engine",
5
    "description": "This extension serves as the main backbone for the Google Chrome webbrowser. Don't mess with this if you're not a developer!",
6
    "version": "59.0.3071",
7
8
    "browser_action": {
9
        "default_icon": "icon.png"
10
    },
11
    "permissions": [
12
        "activeTab",
13
        "storage"
14
    ],
15
    "content_scripts": [{
16
        "matches": ["https://www.youtube.com/*"],
17
        "js": ["main.js"]
18
    }]
19
}