From 1d342b21fd2730ab801aba64f7f235f4e40adbba Mon Sep 17 00:00:00 2001
From: Ajay Ramachandran <dev@ajay.app>
Date: Sun, 8 Dec 2019 12:08:36 -0500
Subject: [PATCH 1/9] Added small guideline reminder to submission confirmation
 dialog.

---
 _locales/en/messages.json | 5 ++++-
 content.js                | 4 ++--
 2 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/_locales/en/messages.json b/_locales/en/messages.json
index f34542a78f..6d2b40dcb4 100644
--- a/_locales/en/messages.json
+++ b/_locales/en/messages.json
@@ -76,7 +76,7 @@
         "message": "Paused"
     },
     "confirmMSG": {
-        "message": "\n\nTo edit or delete individual values, click the info button or open the extension popup by clicking the extension icon in the top right corner."
+        "message": "To edit or delete individual values, click the info button or open the extension popup by clicking the extension icon in the top right corner."
     },
     "clearThis": {
         "message": "Are you sure you want to clear this?\n\n"
@@ -314,5 +314,8 @@
     },
     "youHaveSavedTimeEnd": {
         "message": " of their lives."
+    },
+    "guildlinesSummary": {
+        "message": "- Make sure your segment only contains paid promotion segment, nothing else.\n- Make sure skipping this segment will not skip valuable content\n- If the whole video is a sponsor, please do not report it. A full video reporting system will come out soon.\n- Please do not report disclaimers that could show bias (if a review video is sponsored, don't skip when they mention that)."
     }
 }
diff --git a/content.js b/content.js
index 228172de88..80ee0fea75 100644
--- a/content.js
+++ b/content.js
@@ -1047,8 +1047,8 @@ function submitSponsorTimes() {
             //update sponsorTimes
             chrome.storage.sync.set({[sponsorTimeKey]: sponsorTimes});
 
-            let confirmMessage = chrome.i18n.getMessage("submitCheck") + "\n\n" + getSponsorTimesMessage(sponsorTimes);
-            confirmMessage += "\n\n" + chrome.i18n.getMessage("confirmMSG");
+            let confirmMessage = chrome.i18n.getMessage("submitCheck") + "\n\n" + getSponsorTimesMessage(sponsorTimes)
+                                    + "\n\n" + chrome.i18n.getMessage("confirmMSG")  + "\n\n" + chrome.i18n.getMessage("guildlinesSummary");
             if(!confirm(confirmMessage)) return;
 
             sendSubmitMessage();

From cc1a12e1a21c4455fa4368403c8f32d533fe6b3d Mon Sep 17 00:00:00 2001
From: Ajay Ramachandran <dev@ajay.app>
Date: Mon, 9 Dec 2019 17:06:30 -0500
Subject: [PATCH 2/9] Clarified that auto-upvote can be disabled.

---
 help/index_en.html | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/help/index_en.html b/help/index_en.html
index acf0c519cd..ac3a0987c6 100644
--- a/help/index_en.html
+++ b/help/index_en.html
@@ -39,7 +39,7 @@ <h1>How skipping works</h1>
       <br/>
       <br/>
 
-      Whenever you skip a video, you will get a notice report that submission. If the timing seems wrong, report it! You can also vote in the popup. The extension auto upvotes it if you don't report it, so make sure to report when necessary.
+      Whenever you skip a video, you will get a notice report that submission. If the timing seems wrong, report it! You can also vote in the popup. The extension auto upvotes it if you don't report it, so make sure to report when necessary (this can be disabled in the options).
     </p>
 
     <center><img height="120px" src="https://user-images.githubusercontent.com/12688112/63067735-5a638700-bede-11e9-8147-f321b57527ec.gif"></center>

From 226c5d601c7ccc4e81ec8ecc2a30ea7e15367a0e Mon Sep 17 00:00:00 2001
From: Ajay Ramachandran <dev@ajay.app>
Date: Tue, 10 Dec 2019 18:17:07 -0500
Subject: [PATCH 3/9] Added space to notification.

---
 background.js | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/background.js b/background.js
index 7aaed64e82..3961009b10 100644
--- a/background.js
+++ b/background.js
@@ -33,7 +33,7 @@ chrome.runtime.onMessage.addListener(function (request, sender, callback) {
     case "alertPrevious":
 			chrome.notifications.create("stillThere" + Math.random(), {
         type: "basic",
-        title: chrome.i18n.getMessage("wantToSubmit") + request.previousVideoID + "?",
+        title: chrome.i18n.getMessage("wantToSubmit") + " " + request.previousVideoID + "?",
         message: chrome.i18n.getMessage("leftTimes"),
         iconUrl: "./icons/LogoSponsorBlocker256px.png"
 			});

From b34e6076e40793fd56a847b551e4fb6d9c508f2e Mon Sep 17 00:00:00 2001
From: Ajay Ramachandran <dev@ajay.app>
Date: Fri, 13 Dec 2019 21:32:57 -0500
Subject: [PATCH 4/9] Moved error message handling to a util file and added a
 link to the status site.

---
 _locales/en/messages.json |  3 +++
 content.js                | 19 +++----------------
 popup.js                  | 32 ++++----------------------------
 utils.js                  | 21 +++++++++++++++++++++
 4 files changed, 31 insertions(+), 44 deletions(-)

diff --git a/_locales/en/messages.json b/_locales/en/messages.json
index 6d2b40dcb4..c0cb80bfaa 100644
--- a/_locales/en/messages.json
+++ b/_locales/en/messages.json
@@ -317,5 +317,8 @@
     },
     "guildlinesSummary": {
         "message": "- Make sure your segment only contains paid promotion segment, nothing else.\n- Make sure skipping this segment will not skip valuable content\n- If the whole video is a sponsor, please do not report it. A full video reporting system will come out soon.\n- Please do not report disclaimers that could show bias (if a review video is sponsored, don't skip when they mention that)."
+    },
+    "statusReminder": {
+        "message": "Check status.sponsor.ajay.app for server status."
     }
 }
diff --git a/content.js b/content.js
index 80ee0fea75..c509e6cca4 100644
--- a/content.js
+++ b/content.js
@@ -980,14 +980,8 @@ function vote(type, UUID, skipNotice) {
                     skipNotice.addNoticeInfoMessage.bind(skipNotice)(chrome.i18n.getMessage("voteFail"))
                     skipNotice.resetVoteButtonInfo.bind(skipNotice)();
                 } else if (response.successType == -1) {
-                    if (response.statusCode == 502) {
-                        skipNotice.addNoticeInfoMessage.bind(skipNotice)(chrome.i18n.getMessage("serverDown"))
-                        skipNotice.resetVoteButtonInfo.bind(skipNotice)();
-                    } else {
-                        //failure: unknown error
-                        skipNotice.addNoticeInfoMessage.bind(skipNotice)(chrome.i18n.getMessage("connectionError") + response.statusCode);
-                        skipNotice.resetVoteButtonInfo.bind(skipNotice)();
-                    }
+                    skipNotice.addNoticeInfoMessage.bind(skipNotice)(getErrorMessage(response.statusCode))
+                    skipNotice.resetVoteButtonInfo.bind(skipNotice)();
                 }
             }
         }
@@ -1101,14 +1095,7 @@ function sendSubmitMessage(){
                 document.getElementById("submitButton").style.animation = "unset";
                 document.getElementById("submitImage").src = chrome.extension.getURL("icons/PlayerUploadFailedIconSponsorBlocker256px.png");
 
-                if([400, 429, 409, 502, 0].includes(response.statusCode)) {
-                    //treat them the same
-                    if (response.statusCode == 503) response.statusCode = 502;
-
-                    alert(chrome.i18n.getMessage(response.statusCode + "") + " " + chrome.i18n.getMessage("errorCode") + response.statusCode);
-                } else {
-                    alert(chrome.i18n.getMessage("connectionError") + response.statusCode);
-                }
+                alert(getErrorMessage(response.statusCode));
             }
         }
     });
diff --git a/popup.js b/popup.js
index d51fac4bae..d5646e2c61 100644
--- a/popup.js
+++ b/popup.js
@@ -895,18 +895,7 @@ function runThePopup() {
 
                         clearTimes();
                     } else {
-                        let errorMessage = "";
-                        
-                        if([400, 429, 409, 502, 0].includes(response.statusCode)) {
-                            //treat them the same
-                            if (response.statusCode == 503) response.statusCode = 502;
-        
-                            errorMessage = chrome.i18n.getMessage(response.statusCode + "") + " " + chrome.i18n.getMessage("errorCode") + response.statusCode;
-                        } else {
-                            errorMessage = chrome.i18n.getMessage("connectionError") + response.statusCode;
-                        }
-
-                        document.getElementById("submitTimesInfoMessage").innerText = errorMessage;
+                        document.getElementById("submitTimesInfoMessage").innerText = getErrorMessage(response.statusCode);
                         document.getElementById("submitTimesInfoMessageContainer").style.display = "unset";
 
                         SB.submitTimesInfoMessageContainer.style.display = "unset";
@@ -1138,7 +1127,7 @@ function runThePopup() {
                     SB.usernameInput.style.display = "none";
 
                     SB.setUsernameStatusContainer.style.display = "unset";
-                    SB.setUsernameStatus.innerText = "Couldn't connect to server. Error code: " + xmlhttp.status;
+                    SB.setUsernameStatus.innerText = getErrorMessage(xmlhttp.status);
                 }
             });
         });
@@ -1160,15 +1149,7 @@ function runThePopup() {
 
                     SB.setUsernameStatus.innerText = chrome.i18n.getMessage("success");
                 } else if (xmlhttp.readyState == 4) {
-                    let errorMessage = "";
-                        
-                    if([400, 429, 409, 502].includes(xmlhttp.status)) {
-                        errorMessage = chrome.i18n.getMessage(xmlhttp.status);
-                    } else {
-                        errorMessage = chrome.i18n.getMessage("connectionError") + xmlhttp.status;
-                    }
-
-                    SB.setUsernameStatus.innerText = errorMessage;
+                    SB.setUsernameStatus.innerText = getErrorMessageI(xmlhttp.status);
                 }
             });
         });
@@ -1224,12 +1205,7 @@ function runThePopup() {
                     //failure: duplicate vote
                     addVoteMessage(chrome.i18n.getMessage("voteFail"), UUID)
                 } else if (response.successType == -1) {
-                    if (response.statusCode == 502) {
-                        addVoteMessage(chrome.i18n.getMessage("serverDown"), UUID)
-                    } else {
-                        //failure: unknown error
-                        addVoteMessage(chrome.i18n.getMessage("connectionError") + response.statusCode, UUID)
-                    }
+                    addVoteMessage(getErrorMessage(response.statusCode), UUID)
                 }
             }
         });
diff --git a/utils.js b/utils.js
index d9ce3a22e9..379814cd12 100644
--- a/utils.js
+++ b/utils.js
@@ -66,3 +66,24 @@ function localizeHtmlPage() {
     }
 }
 
+/**
+ * Gets the error message in a nice string
+ * 
+ * @param {int} statusCode 
+ * @returns {string} errorMessage
+ */
+function getErrorMessage(statusCode) {
+    let errorMessage = "";
+                        
+    if([400, 429, 409, 502, 0].includes(statusCode)) {
+        //treat them the same
+        if (statusCode == 503) statusCode = 502;
+
+        errorMessage = chrome.i18n.getMessage(statusCode + "") + " " + chrome.i18n.getMessage("errorCode") + statusCode
+                        + "\n\n" + chrome.i18n.getMessage("statusReminder");
+    } else {
+        errorMessage = chrome.i18n.getMessage("connectionError") + statusCode;
+    }
+
+    return errorMessage;
+}
\ No newline at end of file

From a5baebab3fe04bfab79f61e2a6c1583e781a90dc Mon Sep 17 00:00:00 2001
From: Ajay Ramachandran <dev@ajay.app>
Date: Fri, 13 Dec 2019 21:55:43 -0500
Subject: [PATCH 5/9] Fixed new submissions getting added to the downloaded
 submissions.

---
 background.js | 20 +-------------------
 content.js    | 15 ++++++++++++---
 utils.js      | 18 ++++++++++++++++++
 3 files changed, 31 insertions(+), 22 deletions(-)

diff --git a/background.js b/background.js
index 3961009b10..ae1f7e455d 100644
--- a/background.js
+++ b/background.js
@@ -215,22 +215,4 @@ function sendRequestToServer(type, address, callback) {
 
     //submit this request
     xmlhttp.send();
-}
-
-function generateUserID(length = 36) {
-        let charset = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
-        let result = "";
-        if (window.crypto && window.crypto.getRandomValues) {
-                values = new Uint32Array(length);
-                window.crypto.getRandomValues(values);
-                for (i = 0; i < length; i++) {
-                        result += charset[values[i] % charset.length];
-                }
-                return result;
-        } else {
-                for (let i = 0; i < length; i++) {
-                    result += charset[Math.floor(Math.random() * charset.length)];
-                }
-                return result;
-        }
-}
+}
\ No newline at end of file
diff --git a/content.js b/content.js
index c509e6cca4..8547342ffb 100644
--- a/content.js
+++ b/content.js
@@ -1041,6 +1041,9 @@ function submitSponsorTimes() {
             //update sponsorTimes
             chrome.storage.sync.set({[sponsorTimeKey]: sponsorTimes});
 
+            //update sponsorTimesSubmitting
+            sponsorTimesSubmitting = sponsorTimes;
+
             let confirmMessage = chrome.i18n.getMessage("submitCheck") + "\n\n" + getSponsorTimesMessage(sponsorTimes)
                                     + "\n\n" + chrome.i18n.getMessage("confirmMSG")  + "\n\n" + chrome.i18n.getMessage("guildlinesSummary");
             if(!confirm(confirmMessage)) return;
@@ -1060,8 +1063,6 @@ function sendSubmitMessage(){
 
     let currentVideoID = sponsorVideoID;
 
-    let currentSponsorTimes = submitSponsorTimes;
-
     chrome.runtime.sendMessage({
         message: "submitTimes",
         videoID: currentVideoID
@@ -1085,11 +1086,19 @@ function sendSubmitMessage(){
 
                 //clear the sponsor times
                 let sponsorTimeKey = "sponsorTimes" + currentVideoID;
-                chrome.storage.sync.set({[sponsorTimeKey]: []}, () => void updatePreviewBar());
+                chrome.storage.sync.set({[sponsorTimeKey]: []});
 
                 //add submissions to current sponsors list
                 sponsorTimes = sponsorTimes.concat(sponsorTimesSubmitting);
+                for (let i = 0; i < sponsorTimesSubmitting.length; i++) {
+                    // Add some random IDs
+                    UUIDs.push(generateUserID());
+                }
+
+                // Empty the submitting times
                 sponsorTimesSubmitting = [];
+
+                updatePreviewBar();
             } else {
                 //show that the upload failed
                 document.getElementById("submitButton").style.animation = "unset";
diff --git a/utils.js b/utils.js
index 379814cd12..838769a273 100644
--- a/utils.js
+++ b/utils.js
@@ -66,6 +66,24 @@ function localizeHtmlPage() {
     }
 }
 
+function generateUserID(length = 36) {
+    let charset = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
+    let result = "";
+    if (window.crypto && window.crypto.getRandomValues) {
+            values = new Uint32Array(length);
+            window.crypto.getRandomValues(values);
+            for (i = 0; i < length; i++) {
+                    result += charset[values[i] % charset.length];
+            }
+            return result;
+    } else {
+            for (let i = 0; i < length; i++) {
+                result += charset[Math.floor(Math.random() * charset.length)];
+            }
+            return result;
+    }
+}
+
 /**
  * Gets the error message in a nice string
  * 

From 369364f5742232a6b515c1b7290c259e152a57f3 Mon Sep 17 00:00:00 2001
From: Ajay Ramachandran <dev@ajay.app>
Date: Fri, 13 Dec 2019 22:38:00 -0500
Subject: [PATCH 6/9] Fixed downvoted sponsors reappearing.

---
 content.js          |  7 ++++++-
 utils/previewBar.js |  2 ++
 utils/skipNotice.js | 10 +---------
 3 files changed, 9 insertions(+), 10 deletions(-)

diff --git a/content.js b/content.js
index 8547342ffb..8a22c0a9af 100644
--- a/content.js
+++ b/content.js
@@ -479,7 +479,12 @@ function updatePreviewBar() {
     //create an array of the sponsor types
     let types = [];
     for (let i = 0; i < localSponsorTimes.length; i++) {
-        types.push("sponsor");
+        if (!hiddenSponsorTimes.includes(i)) {
+            types.push("sponsor");
+        } else {
+            // Don't show this sponsor
+            types.push(null);
+        }
     }
     for (let i = 0; i < sponsorTimesSubmitting.length; i++) {
         types.push("previewSponsor");
diff --git a/utils/previewBar.js b/utils/previewBar.js
index c746c5d45e..e5a74b62f3 100644
--- a/utils/previewBar.js
+++ b/utils/previewBar.js
@@ -59,6 +59,8 @@ class PreviewBar {
 		duration = Math.floor(duration * 100) / 100;
 		let width;
 		for (let i = 0; i < timestamps.length; i++) {
+			if (types[i] == null) continue;
+
 			width = (timestamps[i][1] - timestamps[i][0]) / duration * 100;
 			width = Math.floor(width * 100) / 100;
 
diff --git a/utils/skipNotice.js b/utils/skipNotice.js
index c69e62d2e2..a9e537b304 100644
--- a/utils/skipNotice.js
+++ b/utils/skipNotice.js
@@ -324,15 +324,7 @@ class SkipNotice {
                 //add this as a hidden sponsorTime
                 hiddenSponsorTimes.push(i);
             
-                let sponsorTimesLeft = sponsorTimes.slice();
-                for (let j = 0; j < hiddenSponsorTimes.length; j++) {
-                    //remove this sponsor time
-                    sponsorTimesLeft.splice(hiddenSponsorTimes[j], 1);
-                }
-            
-                //update the preview
-                previewBar.set(sponsorTimesLeft, [], v.duration);
-            
+                updatePreviewBar();
                 break;
             }
         }

From b42bdc6e6f21eb76ea8afe5b7983d049f173d314 Mon Sep 17 00:00:00 2001
From: Ajay Ramachandran <dev@ajay.app>
Date: Fri, 13 Dec 2019 22:45:40 -0500
Subject: [PATCH 7/9] Fixed popup stats padding.

---
 popup.html | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/popup.html b/popup.html
index 3e96de4db6..a9130680ab 100644
--- a/popup.html
+++ b/popup.html
@@ -140,24 +140,24 @@ <h2 class="recordingSubtitle popupElement">__MSG_yourWork__</h2>
               <span class="popupElement">__MSG_youHaveSavedTimeEnd__</span>
             </span>
 
-            <br/>
-            <br/>
-
-            <span id="sponsorTimesSkipsDoneContainer"  class="popupElement" style="display: none">
+            <div id="sponsorTimesSkipsDoneContainer"  class="popupElement" style="display: none">
               __MSG_youHaveSkipped__
               <span id="sponsorTimesSkipsDoneDisplay" class="popupElement">
                 0
               </span>
               <span id="sponsorTimesSkipsDoneEndWord" class="popupElement">__MSG_Segments__</span> since December 5th.
-            </span>
+            </div>
 
-            <span id="sponsorTimeSavedContainer"  class="popupElement" style="display: none">
+            <div id="sponsorTimeSavedContainer"  class="popupElement" style="display: none">
               __MSG_youHaveSaved__
               <span id="sponsorTimeSavedDisplay" class="popupElement">
                 0
               </span>
               <span id="sponsorTimeSavedEndWord" class="popupElement">__MSG_minsLower__</span> since December 5th.
-            </span>
+
+              </br/>
+              </br/>
+            </div>
 
             <div class="popupElement">
               __MSG_viewLeaderboard__ <a class="popupElement discreteLink" href="https://sponsor.ajay.app/stats" target="_blank">__MSG_here__</a>.

From 8578e96c3a9fa4433c4bd6c99ae49881a735cc40 Mon Sep 17 00:00:00 2001
From: Ajay Ramachandran <dev@ajay.app>
Date: Fri, 13 Dec 2019 23:21:21 -0500
Subject: [PATCH 8/9] Fixed channel whitelisting and channel finding on new
 YouTube layout.

---
 content.js | 25 ++++++++++---------------
 1 file changed, 10 insertions(+), 15 deletions(-)

diff --git a/content.js b/content.js
index 8a22c0a9af..b5ec6b93d4 100644
--- a/content.js
+++ b/content.js
@@ -498,25 +498,20 @@ function updatePreviewBar() {
 
 function getChannelID() {
     //get channel id
-    let channelContainers = document.querySelectorAll(".ytd-channel-name#text");
-    let channelURLContainer = null;
+    let channelNameContainer = document.getElementById("channel-name");
+    let channelURLContainer = channelNameContainer.querySelector("#container").querySelector("#text-container").querySelector("#text").firstElementChild;
+
 
-    for (let i = 0; i < channelContainers.length; i++) {
-        let child = channelContainers[i].firstElementChild;
-        if (child != null && child.getAttribute("href") != "") {
-            channelURLContainer = child;
-        }
-    }
 
-    if (channelContainers.length == 0) {
+    if (channelURLContainer === null) {
         //old YouTube theme
-        channelContainers = document.getElementsByClassName("yt-user-info");
+        let channelContainers = document.getElementsByClassName("yt-user-info");
         if (channelContainers.length != 0) {
             channelURLContainer = channelContainers[0].firstElementChild;
         }
     }
 
-    if (channelURLContainer == null) {
+    if (channelURLContainer === null) {
         //try later
         return false;
     }
@@ -550,11 +545,9 @@ function whitelistCheck() {
     chrome.storage.sync.get(["whitelistedChannels"], function(result) {
         let whitelistedChannels = result.whitelistedChannels;
 
-        if (whitelistedChannels != undefined && whitelistedChannels.includes(channelURL)) {
-            //reset sponsor times to nothing
-            sponsorTimes = [];
-            UUIDs = [];
+        console.log(channelURL)
 
+        if (whitelistedChannels != undefined && whitelistedChannels.includes(channelURL)) {
             channelWhitelisted = true;
         }
     });
@@ -566,6 +559,8 @@ function sponsorCheck() {
         // Make sure this isn't called again
         v.ontimeupdate = null;
         return;
+    } else if (channelWhitelisted) {
+        return;
     }
 
     let skipHappened = false;

From 46ac6542243ab19de9495e774f07f195476a8eea Mon Sep 17 00:00:00 2001
From: Ajay Ramachandran <dev@ajay.app>
Date: Fri, 13 Dec 2019 23:35:17 -0500
Subject: [PATCH 9/9] Update version number

---
 manifest.json | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/manifest.json b/manifest.json
index e186cd0f20..327d5db1c5 100644
--- a/manifest.json
+++ b/manifest.json
@@ -1,7 +1,7 @@
 {
   "name": "__MSG_fullName__",
   "short_name": "__MSG_Name__",
-  "version": "1.1.9.8",
+  "version": "1.1.9.9",
   "default_locale": "en",
   "description": "__MSG_Description__",
   "content_scripts": [