From b582aa4fbbe34a9db1f74f87105bfffb16e75cbc Mon Sep 17 00:00:00 2001 From: ksjdragon Date: Thu, 26 Feb 2015 19:54:23 -0500 Subject: [PATCH] made base for reading from file --- substitution/manifest.json | 4 ++-- substitution/src/bg/replace.js | 28 +++++++++++++++++++++++++--- substitution/src/bg/test.txt | 7 +++++++ substitution/src/options/index.html | 23 ++++++++++++++++------- 4 files changed, 50 insertions(+), 12 deletions(-) create mode 100644 substitution/src/bg/test.txt diff --git a/substitution/manifest.json b/substitution/manifest.json index 6e77fad..773c6b6 100644 --- a/substitution/manifest.json +++ b/substitution/manifest.json @@ -1,6 +1,6 @@ { "name": "Substitution", - "version": "1.0", + "version": "0.1.1", "manifest_version": 2, "description": "Replaces words for amusement.", "homepage_url": "http://extensionizr.com", @@ -19,7 +19,7 @@ "options_page": "src/options/index.html", "browser_action": { "default_icon": "icons/icon19.png", - "default_title": "browser action demo" + "default_title": "Substitute?" }, "permissions": [ "https://*/*", diff --git a/substitution/src/bg/replace.js b/substitution/src/bg/replace.js index b742fee..be85f2c 100644 --- a/substitution/src/bg/replace.js +++ b/substitution/src/bg/replace.js @@ -1,4 +1,4 @@ -document.documentElement.innerHTML = +/*document.documentElement.innerHTML = document.documentElement.innerHTML .replace(/witnesses/g, "these dudes I know") .replace(/allegedly/g, "kinda probably") @@ -20,5 +20,27 @@ document.documentElement.innerHTML .replace(/radioactive/g, "kinda dangerous") .replace(/Democratic Party/g, "Elephants") .replace(/Republican Party/g, "Donkeys") - .replace(/Democratic-Donkeys/g, "Elephant-Donkeys"); - //add all \ No newline at end of file + .replace(/Democratic-Donkeys/g, "Elephant-Donkeys");*/ +var html = document.documentElement.innerHTML; +var wordsReplacee = []; +var wordsReplacer = []; + +var test = "witnesses these dudes I know\nallegedly kinda probably\npresident garbage man\ngive gib"; +//^ this is where we reference the reading of file +var file = test.split(/[\s]/); + +for( var i = 0; i < file.length ; i+=2 ) { + wordsReplacee.push(file[i]); + wordsReplacer.push(file[i+1]); + console.log(wordsReplacee); + console.log(wordsReplacer); +} + +for( var a = 0; a < wordsReplacee.length; a++ ) { + var reg = new RegExp(wordsReplacee[a], "gi"); + if (a = 0) { + htmlReplaced = html.replace(reg, wordsReplacer); + } else { + htmlReplaced = htmlReplaced.replace(reg, wordsReplacer); + } +} \ No newline at end of file diff --git a/substitution/src/bg/test.txt b/substitution/src/bg/test.txt new file mode 100644 index 0000000..3c7f10a --- /dev/null +++ b/substitution/src/bg/test.txt @@ -0,0 +1,7 @@ +hi +bye +asdf +asdh +asdhasdf +asdhasdddd +asdhasdhasdf \ No newline at end of file diff --git a/substitution/src/options/index.html b/substitution/src/options/index.html index f211c87..b66394e 100644 --- a/substitution/src/options/index.html +++ b/substitution/src/options/index.html @@ -1,9 +1,18 @@ - + - - - - + + + + IA Chromebook Sign-Out - - \ No newline at end of file + + + + + + +

Options

+ + \ No newline at end of file