Skip to content

Instantly share code, notes, and snippets.

@HaKDMoDz
Forked from danharper/background.js
Last active February 10, 2019 07:40
Show Gist options
  • Save HaKDMoDz/2d42cee599a4e685f9a148632bb61476 to your computer and use it in GitHub Desktop.
Save HaKDMoDz/2d42cee599a4e685f9a148632bb61476 to your computer and use it in GitHub Desktop.
Bare minimum Chrome extension to inject a JS file into the given page when you click on the browser action icon. The script then inserts a new div which contains a button element into the DOM! The function of the button is to remove google ads class from current site.
// this is the background code...
// listen for our browserAction to be clicked
chrome.browserAction.onClicked.addListener(function (tab) {
// for the current tab, inject the "inject.js" file & execute it
chrome.tabs.executeScript(tab.ib, {
file: 'inject.js'
});
});
// this is the code which will be injected into a given page...
// containing function to create a div element attached to a button sub element
// the button removes all "adsbygoogle" classes from "ins" elements within the page.
//
(function() {
// just place a div at top right
var div = document.createElement('div');
div.style.position = 'fixed';
div.style.top = 0;
div.style.right = 0;
div.textContent = 'Injected!';
document.body.appendChild(div);
var btn = document.createElement('button');
btn.style.position = 'fixed';
btn.style.backgroundColor = 'dodgerblue';
btn.style.color = 'white';
btn.textContent = 'Remove Google Ads';
alert('Google Ad Removal Button!');
})();
{
"name": "Grief",
"version": "0.0.0",
"manifest_version": 1,
"description": "Injecting a button to remove googleAds class from current site",
"homepage_url": "http://youtube.com/user/hakdmodz/videos/index.html",
"background": {
"scripts": [
"background.js"
],
"persistent": true
},
"icons": { "16": "googleTrashed-Spun.png",
"48": "googleTrashed-Spun.png",
"128": "googleTrashed-Spun.png" },
"browser_action": {
"default_title": "Grief"
},
"author": "HaKDMoDz™",
"permissions": [
"https://*/*",
"http://*/*",
"tabs"
]
}
@HaKDMoDz
Copy link
Author

my fork version attempts to remove those annoying google ads from a web page by using
danharper/background.js injection script for chrome browser extension.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment