commit 11596c3d6df3143c8e7a1fcdcc927470bcee6aa1 Author: Anatoly Kopyl Date: Sat Apr 11 23:09:11 2020 +0300 Initial commit diff --git a/background.js b/background.js new file mode 100644 index 0000000..72c1ea0 --- /dev/null +++ b/background.js @@ -0,0 +1,15 @@ +chrome.runtime.onInstalled.addListener(function() { + chrome.storage.sync.set({isExtensionOn: true}, function() { + console.log('isExtensionOn: '+true); + }); + + chrome.declarativeContent.onPageChanged.removeRules(undefined, function() { + chrome.declarativeContent.onPageChanged.addRules([{ + conditions: [new chrome.declarativeContent.PageStateMatcher({ + pageUrl: {hostEquals: 'vk.com'}, + }) + ], + actions: [new chrome.declarativeContent.ShowPageAction()] + }]); + }); + }); \ No newline at end of file diff --git a/hide_element.js b/hide_element.js new file mode 100644 index 0000000..3523322 --- /dev/null +++ b/hide_element.js @@ -0,0 +1,21 @@ +var idToHide; + +function hidePeer(peer) { + chrome.storage.sync.get('idToHide', function(data) { + idToHide = data.idToHide + }); + + chrome.storage.sync.get('isExtensionOn', function(data) { + if (data.isExtensionOn) { + var x = document.querySelectorAll('[data-peer="'+peer+'"]'); + + x.forEach( + function(val) { + val.style.display = "none"; + } + ) + } + }); +} + +var interval = window.setInterval(function(){ hidePeer(idToHide) }, 500); diff --git a/manifest.json b/manifest.json new file mode 100644 index 0000000..5c7b0c9 --- /dev/null +++ b/manifest.json @@ -0,0 +1,24 @@ +{ + "name": "Hide Cringe", + "version": "1.0", + "description": "Hides cringe", + "permissions": ["activeTab", "declarativeContent", "storage"], + "background": { + "scripts": [ + "background.js" + ], + "persistent": false + }, + "page_action": { + "default_popup": "popup.html" + }, + "manifest_version": 2, + "content_scripts": [ + { + "matches": [ + "https://*.vk.com/*" + ], + "js": ["hide_element.js"] + } + ] +} diff --git a/popup.html b/popup.html new file mode 100644 index 0000000..01066d9 --- /dev/null +++ b/popup.html @@ -0,0 +1,104 @@ + + + + + + + +
+ +

+
+ +
+ +
+ + + \ No newline at end of file diff --git a/popup.js b/popup.js new file mode 100644 index 0000000..8db6b7a --- /dev/null +++ b/popup.js @@ -0,0 +1,59 @@ +//let disableButton = document.getElementById('disableButton'); +let disableCheckbox = document.getElementById('disableCheckbox'); +let idToHideInput = document.getElementById('idToHide'); +let status = document.getElementById('status'); +var isExtensionOn; +var idToHide; + +var enableText = "Кринж офф"; +var disableText = "Кринж он"; + +chrome.storage.sync.get('isExtensionOn', function(data) { + isExtensionOn = data.isExtensionOn; + + disableCheckbox.checked = isExtensionOn; + if (isExtensionOn) { + status.innerHTML = enableText; + } else { + status.innerHTML = disableText; + } +}); + +chrome.storage.sync.get('idToHide', function(data) { + idToHide = data.idToHide; + idToHideInput.value = idToHide; +}); + + +/*disableButton.onclick = function(element) { + isExtensionOn = !isExtensionOn; + if (isExtensionOn) { + status.innerHTML = "Enabled"; + } else { + status.innerHTML = "Disabled"; + } + + chrome.storage.sync.set({isExtensionOn: isExtensionOn}, function() { + console.log('isExtensionOn: '+isExtensionOn); + }); +};*/ + +disableCheckbox.addEventListener('change', (event) => { + isExtensionOn = event.target.checked; + if (event.target.checked) { + status.innerHTML = enableText; + } else { + status.innerHTML = disableText; + } + + chrome.storage.sync.set({isExtensionOn: isExtensionOn}, function() { + console.log('isExtensionOn: '+isExtensionOn); + }); +}); + +idToHideInput.addEventListener('input', (event) => { + chrome.storage.sync.set({idToHide: idToHideInput.value}, function() { + console.log('idToHide: '+idToHideInput.value); + }); +}); +