Skip to content

Instantly share code, notes, and snippets.

@jmeyo
Forked from danharper/background.js
Last active March 2, 2016 02:34

Revisions

  1. jmeyo revised this gist Mar 2, 2016. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions manifest.json
    Original file line number Diff line number Diff line change
    @@ -1,9 +1,9 @@
    {
    "name": "Injecta",
    "name": "Victor",
    "version": "0.0.1",
    "manifest_version": 2,
    "description": "Injecting stuff",
    "homepage_url": "http://danharper.me",
    "homepage_url": "http://www.houseofagile.com",
    "background": {
    "scripts": [
    "background.js"
  2. jmeyo revised this gist Mar 1, 2016. 1 changed file with 42 additions and 8 deletions.
    50 changes: 42 additions & 8 deletions inject.js
    Original file line number Diff line number Diff line change
    @@ -1,15 +1,49 @@
    // this is the code which will be injected into a given page...

    (function() {

    walk(document.body);

    // 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);
    function walk(node)
    {
    // I stole this function from here:
    // http://is.gd/mwZp7E

    var child, next;

    if (node.tagName.toLowerCase() == 'input' || node.tagName.toLowerCase() == 'textarea'
    || node.classList.indexOf('ace_editor') > -1) {
    return;
    }

    switch ( node.nodeType )
    {
    case 1: // Element
    case 9: // Document
    case 11: // Document fragment
    child = node.firstChild;
    while ( child )
    {
    next = child.nextSibling;
    walk(child);
    child = next;
    }
    break;

    case 3: // Text node
    handleText(node);
    break;
    }
    }

    function handleText(textNode)
    {
    var v = textNode.nodeValue;

    v = v.replace(/\bTrump\b/g, "Drumpf");

    textNode.nodeValue = v;
    }

    alert('inserted self... giggity');

    })();
  3. @danharper danharper revised this gist Jan 10, 2014. 2 changed files with 2 additions and 2 deletions.
    2 changes: 1 addition & 1 deletion background.js
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,7 @@

    // listen for our browerAction to be clicked
    chrome.browserAction.onClicked.addListener(function (tab) {
    // for the current tab, inject the "inject.js" file & execute it
    // for the current tab, inject the "inject.js" file & execute it
    chrome.tabs.executeScript(tab.ib, {
    file: 'inject.js'
    });
    2 changes: 1 addition & 1 deletion inject.js
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,7 @@

    (function() {

    // just place a div at top right
    // just place a div at top right
    var div = document.createElement('div');
    div.style.position = 'fixed';
    div.style.top = 0;
  4. @danharper danharper created this gist Jan 10, 2014.
    9 changes: 9 additions & 0 deletions background.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,9 @@
    // this is the background code...

    // listen for our browerAction 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'
    });
    });
    15 changes: 15 additions & 0 deletions inject.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    // this is the code which will be injected into a given 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);

    alert('inserted self... giggity');

    })();
    21 changes: 21 additions & 0 deletions manifest.json
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    {
    "name": "Injecta",
    "version": "0.0.1",
    "manifest_version": 2,
    "description": "Injecting stuff",
    "homepage_url": "http://danharper.me",
    "background": {
    "scripts": [
    "background.js"
    ],
    "persistent": true
    },
    "browser_action": {
    "default_title": "Inject!"
    },
    "permissions": [
    "https://*/*",
    "http://*/*",
    "tabs"
    ]
    }