From 91034e3b23e957aeac29f867876f5a4cb0e95cd0 Mon Sep 17 00:00:00 2001 From: Victor Savinov Date: Sun, 13 Oct 2019 01:53:27 +0300 Subject: [PATCH] few fixes --- 2.0/_locales/en/messages.json | 42 +++++++++---------- 2.0/background.js | 25 ++++++++++- 2.0/manifest.json | 3 +- 2.0/satus/components/js/shortcut.js | 8 ++++ 2.0/satus/components/js/switch.js | 9 +++- 2.0/satus/core.js | 40 ++++++++++++++++++ 2.0/satus/index.html | 2 +- 2.0/satus/modules/js/chromium-storage.js | 29 +++++++++++++ .../{youtube-time.js => analyzer.js} | 2 +- 2.0/youtube/js/features/analyzer.js | 2 +- 10 files changed, 134 insertions(+), 28 deletions(-) rename 2.0/satus/templates/improvedtube/template-parts/{youtube-time.js => analyzer.js} (99%) diff --git a/2.0/_locales/en/messages.json b/2.0/_locales/en/messages.json index cbe3ae76a..ea7549caf 100644 --- a/2.0/_locales/en/messages.json +++ b/2.0/_locales/en/messages.json @@ -2,9 +2,6 @@ "about": { "message": "About" }, - "saveAs": { - "message": "Save us" - }, "activateCaptions": { "message": "Activate captions" }, @@ -38,9 +35,6 @@ "annotations": { "message": "Annotations" }, - "hideAnnotations": { - "message": "Hide annotations" - }, "appearance": { "message": "Appearance" }, @@ -110,9 +104,6 @@ "cancel": { "message": "Cancel" }, - "hideCards": { - "message": "Hide cards" - }, "channel": { "message": "Channel" }, @@ -206,9 +197,6 @@ "enabled": { "message": "Enabled" }, - "hideEndscreen": { - "message": "Hide endscreen" - }, "expanded": { "message": "Expanded" }, @@ -218,18 +206,12 @@ "extension": { "message": "Extension" }, - "hideFeaturedContent": { - "message": "Hide featured content" - }, "fitToWindow": { "message": "Fit to window" }, "flash": { "message": "Flash" }, - "hideFooter": { - "message": "Hide footer" - }, "footer": { "message": "Footer" }, @@ -278,12 +260,30 @@ "hideAnimatedThumbnails": { "message": "Hide animated thumbnails" }, + "hideAnnotations": { + "message": "Hide annotations" + }, + "hideCards": { + "message": "Hide cards" + }, "hideDetails": { "message": "Hide details" }, + "hideEndscreen": { + "message": "Hide endscreen" + }, + "hideFeaturedContent": { + "message": "Hide featured content" + }, + "hideFooter": { + "message": "Hide footer" + }, "hideRightButtons": { "message": "Hide right buttons" }, + "hideViewsCount": { + "message": "Hide views count" + }, "history": { "message": "History" }, @@ -494,6 +494,9 @@ "save": { "message": "Save" }, + "saveAs": { + "message": "Save us" + }, "schedule": { "message": "Schedule" }, @@ -608,9 +611,6 @@ "videos": { "message": "Videos" }, - "hideViewsCount": { - "message": "Hide views count" - }, "volume": { "message": "Volume" }, diff --git a/2.0/background.js b/2.0/background.js index 2f47ac21a..82a99686c 100644 --- a/2.0/background.js +++ b/2.0/background.js @@ -8,6 +8,7 @@ 5.0 Storage change listener 6.0 Initialization 7.0 Uninstall URL +8.0 Google analytics --------------------------------------------------------------*/ /*----------------------------------------------------------------------------- @@ -286,4 +287,26 @@ chrome.storage.local.get(function(items) { 7.0 Uninstall URL -----------------------------------------------------------------------------*/ -chrome.runtime.setUninstallURL('http://improvedtube.com/uninstalled'); \ No newline at end of file +chrome.runtime.setUninstallURL('http://improvedtube.com/uninstalled'); + + +/*----------------------------------------------------------------------------- +8.0 Google analytics +-----------------------------------------------------------------------------*/ + +if (chrome.runtime.getManifest().version === chrome.runtime.getManifest().version_name) { + var _gaq = _gaq || []; + + _gaq.push(['_setAccount', 'UA-88354155-1']); + _gaq.push(['_setSessionCookieTimeout', 14400000]); + + (function() { + var ga = document.createElement('script'), + s = document.getElementsByTagName('script')[0]; + + ga.type = 'text/javascript'; + ga.async = true; + ga.src = 'https://ssl.google-analytics.com/ga.js'; + s.parentNode.insertBefore(ga, s); + })(); +} \ No newline at end of file diff --git a/2.0/manifest.json b/2.0/manifest.json index c5360ca2d..2ff3b9935 100644 --- a/2.0/manifest.json +++ b/2.0/manifest.json @@ -66,6 +66,7 @@ "youtube/js/features/channel.js", "youtube/js/features/shortcuts.js", "youtube/js/features/volume-mixer.js", + "youtube/js/features/analyzer.js", "youtube/js/features/blacklist.js", "youtube/js/features/settings.js" ], @@ -146,7 +147,7 @@ "satus/templates/improvedtube/template-parts/channel.js", "satus/templates/improvedtube/template-parts/shortcuts.js", "satus/templates/improvedtube/template-parts/mixer.js", - "satus/templates/improvedtube/template-parts/youtube-time.js", + "satus/templates/improvedtube/template-parts/analyzer.js", "satus/templates/improvedtube/template-parts/blacklist.js", "satus/templates/improvedtube/template-parts/settings.js", "satus/templates/improvedtube/index.js" diff --git a/2.0/satus/components/js/shortcut.js b/2.0/satus/components/js/shortcut.js index ad1760ef9..7b9be1b9c 100644 --- a/2.0/satus/components/js/shortcut.js +++ b/2.0/satus/components/js/shortcut.js @@ -76,6 +76,7 @@ Satus.prototype.components.shortcut = { component_surface = document.createElement('div'), component_canvas = document.createElement('div'), component_section = document.createElement('section'), + component_button_reset = document.createElement('div'), component_button_cancel = document.createElement('div'), component_button_save = document.createElement('div'); @@ -85,10 +86,12 @@ Satus.prototype.components.shortcut = { component_surface.className = 'satus-dialog__surface satus-dialog__surface_shortcut'; component_canvas.className = 'satus-shortcut__canvas'; component_section.className = 'satus-section satus-section_shortcut'; + component_button_reset.className = 'satus-button satus-button_shortcut'; component_button_cancel.className = 'satus-button satus-button_shortcut'; component_button_save.className = 'satus-button satus-button_shortcut'; component_dialog_label.innerText = component_label.innerText; + component_button_reset.innerText = self.storage.get('locale/reset'); component_button_cancel.innerText = self.storage.get('locale/cancel'); component_button_save.innerText = self.storage.get('locale/save'); @@ -140,12 +143,17 @@ Satus.prototype.components.shortcut = { } component_scrim.addEventListener('click', close); + component_button_reset.addEventListener('click', function() { + self.storage.remove(name); + close(); + }); component_button_cancel.addEventListener('click', close); component_button_save.addEventListener('click', function() { self.storage.set(name, JSON.stringify(value)); close(false); }); + component_section.appendChild(component_button_reset); component_section.appendChild(component_button_cancel); component_section.appendChild(component_button_save); diff --git a/2.0/satus/components/js/switch.js b/2.0/satus/components/js/switch.js index 402e27d81..5cf2cdb9a 100644 --- a/2.0/satus/components/js/switch.js +++ b/2.0/satus/components/js/switch.js @@ -12,7 +12,8 @@ Satus.prototype.components.switch = { get: function(name, object) { var self = this, component = document.createElement('div'), - label = this.storage.get('locale/' + object.label) || this.storage.get('locale/' + name) || object.label; + label = this.storage.get('locale/' + object.label) || this.storage.get('locale/' + name) || object.label, + stor = this.storage.get((object.storage_path || '') + '/' + name); object.tabindex = true; @@ -21,7 +22,11 @@ Satus.prototype.components.switch = { ((object.icons || {}).start || '') + '
' + ((object.icons || {}).end || '') + ''; - component.dataset.value = this.storage.get((object.storage_path || '') + '/' + name) || object.value || false; + component.dataset.value = object.value || false; + + if (this.storage.has(name)) { + component.dataset.value = stor; + } component.addEventListener('click', function(event) { if (component.dataset.value == 'true') { diff --git a/2.0/satus/core.js b/2.0/satus/core.js index 936b300bd..f1356e67f 100644 --- a/2.0/satus/core.js +++ b/2.0/satus/core.js @@ -23,6 +23,7 @@ function Satus(query, options = {}) { storage: { get: [], set: [], + remove: [], clear: [] }, components: { @@ -69,6 +70,12 @@ function Satus(query, options = {}) { } }); + Object.defineProperty(this.storage, 'onremove', { + value: function(callback) { + event_listeners.storage.remove.push(callback); + } + }); + Object.defineProperty(this.storage, 'onclear', { value: function(callback) { event_listeners.storage.clear.push(callback); @@ -106,6 +113,7 @@ function Satus(query, options = {}) { Object.defineProperty(this.storage, 'has', { value: function(name) { + console.log(name, storage.hasOwnProperty(name), storage); return storage.hasOwnProperty(name); } }); @@ -142,6 +150,38 @@ function Satus(query, options = {}) { } }); + Object.defineProperty(this.storage, 'remove', { + value: function(name, path) { + if (typeof path === 'string') { + let path_array_before = path.split('/'), + path_array = [], + storage_link = storage; + + for (let i = 0, l = path_array_before.length; i < l; i++) { + if (path_array_before[i] != '') { + path_array.push(path_array_before[i]); + } + } + + for (let i = 0, l = path_array.length; i < l; i++) { + if (!storage_link.hasOwnProperty(path_array[i])) { + storage_link[path_array[i]] = {}; + } + + storage_link = storage_link[path_array[i]]; + } + + delete storage_link[name]; + } else { + delete storage[name]; + } + + for (var i in event_listeners.storage.remove) { + event_listeners.storage.remove[i](name, storage); + } + } + }); + Object.defineProperty(this.storage, 'clear', { value: function() { storage = {}; diff --git a/2.0/satus/index.html b/2.0/satus/index.html index 191f68035..dd7e4d8a6 100644 --- a/2.0/satus/index.html +++ b/2.0/satus/index.html @@ -64,7 +64,7 @@ - + diff --git a/2.0/satus/modules/js/chromium-storage.js b/2.0/satus/modules/js/chromium-storage.js index a8c58dd0f..f126f8a2e 100644 --- a/2.0/satus/modules/js/chromium-storage.js +++ b/2.0/satus/modules/js/chromium-storage.js @@ -17,6 +17,10 @@ Satus.prototype.modules.chromium_storage = { self.set(name, value, storage); }); + self.storage.onremove(function(name, storage) { + self.remove(name, storage); + }); + self.storage.onclear(function() { self.clear(); }); @@ -50,6 +54,31 @@ Satus.prototype.modules.chromium_storage = { } }, + remove: function(name, old_storage) { + var new_storage = {}, + message = { + name: name, + value: null, + storage: this.storage.get() + }, + exclude = this.getOption('chromium_storage').exclude; + + chrome.storage.local.clear(); + chrome.storage.local.set(old_storage); + + if (Object.keys(message).length > 0) { + if (chrome && chrome.tabs) { + chrome.tabs.query({}, function(tabs) { + for (var i = 0, l = tabs.length; i < l; i++) { + if (tabs[i].hasOwnProperty('url')) { + chrome.tabs.sendMessage(tabs[i].id, message); + } + } + }); + } + } + }, + clear: function() { chrome.storage.local.clear(); }, diff --git a/2.0/satus/templates/improvedtube/template-parts/youtube-time.js b/2.0/satus/templates/improvedtube/template-parts/analyzer.js similarity index 99% rename from 2.0/satus/templates/improvedtube/template-parts/youtube-time.js rename to 2.0/satus/templates/improvedtube/template-parts/analyzer.js index a06fd8034..1c66f5b14 100644 --- a/2.0/satus/templates/improvedtube/template-parts/youtube-time.js +++ b/2.0/satus/templates/improvedtube/template-parts/analyzer.js @@ -1,4 +1,4 @@ -Satus.prototype.menu.main.youtube_time = { +Satus.prototype.menu.main.analyzer = { type: 'directory', label: 'analyzer', icon: '', diff --git a/2.0/youtube/js/features/analyzer.js b/2.0/youtube/js/features/analyzer.js index a2ed11e10..dc758ad94 100644 --- a/2.0/youtube/js/features/analyzer.js +++ b/2.0/youtube/js/features/analyzer.js @@ -1,4 +1,4 @@ -ImprovedTube.videoUrl = ''; +ImprovedTube.videoUrl = '"null"'; ImprovedTube.playingTime = 0; document.addEventListener('ImprovedTubeAnalyzer', function() {