From f96147b0ba2ace46cfa9948fd312f21c3b0596b6 Mon Sep 17 00:00:00 2001 From: Andrew Crites Date: Wed, 23 Jul 2014 10:25:18 -0400 Subject: [PATCH] Formatting fixes + .editorconfig * Removed trailing whitespace * Use 4-space tab in JavaScript files consistently --- Source/.editorconfig | 3 + Source/background.js | 2 +- Source/content_script.js | 275 ++++++++++++++++---------------- Source/dictionaries/original.js | 150 ++++++++--------- Source/javascript.vim | 2 - Source/manifest.json | 36 ++--- 6 files changed, 234 insertions(+), 234 deletions(-) create mode 100644 Source/.editorconfig delete mode 100644 Source/javascript.vim diff --git a/Source/.editorconfig b/Source/.editorconfig new file mode 100644 index 0000000..c222acb --- /dev/null +++ b/Source/.editorconfig @@ -0,0 +1,3 @@ +[**.js] +indent_style = space +indent_size = 6 diff --git a/Source/background.js b/Source/background.js index 4353807..e63a0e5 100644 --- a/Source/background.js +++ b/Source/background.js @@ -33,7 +33,7 @@ _alreadyQueued = false; checkForRandomSwap(); }, pollTimeout); - + _alreadyQueued = true; } } diff --git a/Source/content_script.js b/Source/content_script.js index d7ae82a..19e0792 100644 --- a/Source/content_script.js +++ b/Source/content_script.js @@ -1,155 +1,154 @@ (function() { - var _self = this; - var _dictionary; - - function getDictionary(callback) { - chrome.extension.sendRequest({id: "getDictionary"}, function(response) { - _dictionary = response; // Store the dictionary for later use. - callback.apply(_self, arguments); - }); - } - - function handleText(textNode) { - var replacements = _dictionary.replacements; - var expressions = _dictionary.expressions; - var v = textNode.nodeValue; - var matchFound = false; - - var regex, original; - - //text replacements - for(original in replacements) { - original_escaped = original; - - regex_for_question_mark = /\?/g - regex_for_period = /\./g - - original_escaped = original_escaped.replace(regex_for_question_mark, "\\?"); - original_escaped = original_escaped.replace(regex_for_period, "\\."); - - regex = new RegExp('\\b' + original_escaped + '\\b', "gi"); - if (v.match(regex)) { - v = v.replace(regex, replacements[original]); - matchFound = true; - } - - } - - // regex replacements - for(original in expressions) { - regex = new RegExp(original, "g"); - if (v.match(regex)) { - v = v.replace(regex, expressions[original]); - matchFound = true; - } - - } - - // Only change the node if there was any actual text change - if (matchFound) { - textNode.nodeValue = v; - } - - } - - function walk(node) { - - // I stole this function from here: - ZW - // And I stole it from ZW - AG - // http://is.gd/mwZp7E - - var child, next; - - 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; - } - } - - - - // Flag to prevent multiple triggering of DOMSubtreeModified - // set it to true initially so that the DOMSubtreeModified event - // does not trigger work until the two chrome.extension requests - // have been handled - var running = true; - - - // Function that calls walk() but makes sure that it only is called once - // the first call has finished. Any changes that we make to the DOM in walk() - // will trigget DOMSubtreeModified, so we handle this by using the running flag - function work() { - // Set running to true to prevent more calls until the first one is done - running = true; - - // Go through the DOM - walk(document.body); - - // Set running to false to allow additional calls - running = false; - } - - - - chrome.extension.sendRequest({id: 'isPaused?'}, function(response) { - var isPaused = response.value; - - // If the extension is paused, no need to try to call getExcluded - if(isPaused) { - return; + var _self = this; + var _dictionary; + + function getDictionary(callback) { + chrome.extension.sendRequest({id: "getDictionary"}, function(response) { + _dictionary = response; // Store the dictionary for later use. + callback.apply(_self, arguments); + }); } - - chrome.extension.sendRequest({id: 'getExcluded'}, function (r2) { - - var ex = r2.value; - for (x in ex) { - if (window.location.href.indexOf(ex[x]) != -1) { - return; + + function handleText(textNode) { + var replacements = _dictionary.replacements; + var expressions = _dictionary.expressions; + var v = textNode.nodeValue; + var matchFound = false; + + var regex, original; + + //text replacements + for(original in replacements) { + if (replacements.hasOwnProperty(original)) { + original_escaped = original; + + regex_for_question_mark = /\?/g + regex_for_period = /\./g + + original_escaped = original_escaped.replace(regex_for_question_mark, "\\?"); + original_escaped = original_escaped.replace(regex_for_period, "\\."); + + regex = new RegExp('\\b' + original_escaped + '\\b', "gi"); + if (v.match(regex)) { + v = v.replace(regex, replacements[original]); + matchFound = true; + } } } - getDictionary(function() { - work(); + // regex replacements + for(original in expressions) { + regex = new RegExp(original, "g"); + if (v.match(regex)) { + v = v.replace(regex, expressions[original]); + matchFound = true; + } + } + + // Only change the node if there was any actual text change + if (matchFound) { + textNode.nodeValue = v; + } + } + + function walk(node) { + + // I stole this function from here: - ZW + // And I stole it from ZW - AG + // http://is.gd/mwZp7E + + var child, next; + + 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; + } + } + + + + // Flag to prevent multiple triggering of DOMSubtreeModified + // set it to true initially so that the DOMSubtreeModified event + // does not trigger work until the two chrome.extension requests + // have been handled + var running = true; + + + // Function that calls walk() but makes sure that it only is called once + // the first call has finished. Any changes that we make to the DOM in walk() + // will trigget DOMSubtreeModified, so we handle this by using the running flag + function work() { + // Set running to true to prevent more calls until the first one is done + running = true; + + // Go through the DOM + walk(document.body); + + // Set running to false to allow additional calls + running = false; + } + + + + chrome.extension.sendRequest({id: 'isPaused?'}, function(response) { + var isPaused = response.value; + + // If the extension is paused, no need to try to call getExcluded + if(isPaused) { + return; + } + + chrome.extension.sendRequest({id: 'getExcluded'}, function (r2) { + + var ex = r2.value; + for (x in ex) { + if (window.location.href.indexOf(ex[x]) != -1) { + return; + } + } + + getDictionary(function() { + work(); + }); }); - }); - }); + }); - /** - The below solution to handle dynamically added content - is borrowed from http://stackoverflow.com/a/7326468 - */ + /** + The below solution to handle dynamically added content + is borrowed from http://stackoverflow.com/a/7326468 + */ - // Add a timer to prevent instant triggering on each DOM change - var timeout = null; + // Add a timer to prevent instant triggering on each DOM change + var timeout = null; - // Add an eventlistener for changes to the DOM, e.g. new content has been loaded via AJAX or similar - // Any changes that we do to the DOM will trigger this event, so we need to prevent infinite looping - // by checking the running flag first. - document.addEventListener('DOMSubtreeModified', function(){ - if (running) { - return; - } + // Add an eventlistener for changes to the DOM, e.g. new content has been loaded via AJAX or similar + // Any changes that we do to the DOM will trigger this event, so we need to prevent infinite looping + // by checking the running flag first. + document.addEventListener('DOMSubtreeModified', function(){ + if (running) { + return; + } - if (timeout) { - clearTimeout(timeout); - } + if (timeout) { + clearTimeout(timeout); + } - timeout = setTimeout(work, 500); - }, false); + timeout = setTimeout(work, 500); + }, false); })(); diff --git a/Source/dictionaries/original.js b/Source/dictionaries/original.js index 525fef7..590c2fb 100644 --- a/Source/dictionaries/original.js +++ b/Source/dictionaries/original.js @@ -1,80 +1,80 @@ var dictionary={ - "replacements": { - "A Single" : "A", - "Absolutely" : "Moderately", - "Amazing" : "Barely Noticeable", - "Awesome" : "Probably Slightly Less Boring Than Working", - "Best" : "Most Unexceptional", - "Breathtaking" : "Fleetingly Inspirational", - "But what happened next" : "And As You Expect It", - "Can change your life" : "Will Not Change Your Life in ANY Meaningful Way", - "Can't Even Handle" : "Can Totally Handle Without Any Significant Issue", - "Can't Handle" : "Can Totally Handle Without Any Significant Issue", - "Cannot Even Handle" : "Can Probably Totally Handle", - "Doesn't want you to see" : "Doesn't Really Care If You See", - "Epic" : "Mundane", - "Go Viral" : "Be Overused So Much That You'll Silently Pray for the Sweet Release of Death to Make it Stop", - "Greatest" : "Average", - "Incredible" : "Painfully Ordinary", - "Infuriate" : "Mildly Annoy", - "Literally" : "Figuratively", - "Mind Blowing" : "Mind-Numbingly Ordinary", - "Mind-Blowing" : "Painfully Ordinary", - "Mind BLOWN" : "Meh", - "Mind Blown" : "Meh", - "Nothing Could Prepare Me For" : "Does ANYONE Fucking Care About", - "Of All Time" : "For Now", - "Of All Time" : "Of The Last 30 Seconds", - "Of All-Time" : "For Now", - "OMG" : "*yawn*", - "OMG" : "No One Cares. At All", - "One Weird Trick" : "One Piece of Completely Anecdotal Horseshit", - "Perfection" : "Mediocrity", - "Priceless" : "Painfully Ordinary", - "Right Now" : "Eventually", - "Scientific Reasons" : "Vaguely Science-y Reasons", - "Shocked" : "Vaguely Surprised", - "Shocking" : "Barely Noticeable", - "Simple Lessons" : "Inane Pieces of Bullshit Advice", - "Stop What You're Doing" : "Bookmark Now and Later Completely Forget About", - "Stop What You’re Doing" : "Bookmark Now and Later Completely Forget About", - "Stop What You’re Doing" : "Bookmark Now and Later Completely Forget About", - "TERRIFYING" : "MODERATELY UNCOMFORTABLE", - "Terrifying" : "Thoroughly Banal", - "That Will Make You Rethink" : "That You May Find Vaguely Interesting But Won't Change Your Life in Any Way", - "This Is What Happens" : "This Is Our Bullshit Clickbait Version Of What Happens", - "Totally blew my mind" : "Bored Me To Tears", - "Unbelievable" : "Painfully Ordinary", - "Unimaginable" : "Actually Kind of Droll", - "WHAT?" : "Some Other Crap", - "Whoa" : "*yawn*", - "WHOA" : "Zzzzzzzzzzz", - "Whoah" : "*yawn*", - "Will Blow Your Mind" : "Might Perhaps Mildly Entertain You For a Moment", - "Will Change Your Life Forever" : "Will Not Change Your Life in ANY Meaningful or Lasting Way", - "Won the Internet" : "Seemed Pretty Cool", - "Wonderful" : "Mildly Decent", - "Worst" : "Vaguely Unpleasant", - "Wow" : "Oh GOD This is SO Boring. Please Kill Me", - "WOW" : "Zzzzzzzzzzz", - "You Didn't Know Exist" : "No One Gives a Shit About", - "You Didn't Know Existed" : "No One Gives a Shit About", - "You Didn’t Know Exist" : "No One Gives a Shit About", - "You Didn’t Know Existed" : "No One Gives a Shit About", - "You Didn’t Know Exist" : "No One Gives a Shit About", - "You Didn’t Know Existed" : "No One Gives a Shit About", - "You Won't Believe" : "In All Likelihood, You'll Believe", - "You Won’t Believe" : "In All Likelihood, You'll Believe", - "You Won’t Believe" : "In All Likelihood, You'll Believe", - "You Wont Believe" : "In All Likelihood, You'll Believe" - }, - + "replacements": { + "A Single" : "A", + "Absolutely" : "Moderately", + "Amazing" : "Barely Noticeable", + "Awesome" : "Probably Slightly Less Boring Than Working", + "Best" : "Most Unexceptional", + "Breathtaking" : "Fleetingly Inspirational", + "But what happened next" : "And As You Expect It", + "Can change your life" : "Will Not Change Your Life in ANY Meaningful Way", + "Can't Even Handle" : "Can Totally Handle Without Any Significant Issue", + "Can't Handle" : "Can Totally Handle Without Any Significant Issue", + "Cannot Even Handle" : "Can Probably Totally Handle", + "Doesn't want you to see" : "Doesn't Really Care If You See", + "Epic" : "Mundane", + "Go Viral" : "Be Overused So Much That You'll Silently Pray for the Sweet Release of Death to Make it Stop", + "Greatest" : "Average", + "Incredible" : "Painfully Ordinary", + "Infuriate" : "Mildly Annoy", + "Literally" : "Figuratively", + "Mind Blowing" : "Mind-Numbingly Ordinary", + "Mind-Blowing" : "Painfully Ordinary", + "Mind BLOWN" : "Meh", + "Mind Blown" : "Meh", + "Nothing Could Prepare Me For" : "Does ANYONE Fucking Care About", + "Of All Time" : "For Now", + "Of All Time" : "Of The Last 30 Seconds", + "Of All-Time" : "For Now", + "OMG" : "*yawn*", + "OMG" : "No One Cares. At All", + "One Weird Trick" : "One Piece of Completely Anecdotal Horseshit", + "Perfection" : "Mediocrity", + "Priceless" : "Painfully Ordinary", + "Right Now" : "Eventually", + "Scientific Reasons" : "Vaguely Science-y Reasons", + "Shocked" : "Vaguely Surprised", + "Shocking" : "Barely Noticeable", + "Simple Lessons" : "Inane Pieces of Bullshit Advice", + "Stop What You're Doing" : "Bookmark Now and Later Completely Forget About", + "Stop What You’re Doing" : "Bookmark Now and Later Completely Forget About", + "Stop What You’re Doing" : "Bookmark Now and Later Completely Forget About", + "TERRIFYING" : "MODERATELY UNCOMFORTABLE", + "Terrifying" : "Thoroughly Banal", + "That Will Make You Rethink" : "That You May Find Vaguely Interesting But Won't Change Your Life in Any Way", + "This Is What Happens" : "This Is Our Bullshit Clickbait Version Of What Happens", + "Totally blew my mind" : "Bored Me To Tears", + "Unbelievable" : "Painfully Ordinary", + "Unimaginable" : "Actually Kind of Droll", + "WHAT?" : "Some Other Crap", + "Whoa" : "*yawn*", + "WHOA" : "Zzzzzzzzzzz", + "Whoah" : "*yawn*", + "Will Blow Your Mind" : "Might Perhaps Mildly Entertain You For a Moment", + "Will Change Your Life Forever" : "Will Not Change Your Life in ANY Meaningful or Lasting Way", + "Won the Internet" : "Seemed Pretty Cool", + "Wonderful" : "Mildly Decent", + "Worst" : "Vaguely Unpleasant", + "Wow" : "Oh GOD This is SO Boring. Please Kill Me", + "WOW" : "Zzzzzzzzzzz", + "You Didn't Know Exist" : "No One Gives a Shit About", + "You Didn't Know Existed" : "No One Gives a Shit About", + "You Didn’t Know Exist" : "No One Gives a Shit About", + "You Didn’t Know Existed" : "No One Gives a Shit About", + "You Didn’t Know Exist" : "No One Gives a Shit About", + "You Didn’t Know Existed" : "No One Gives a Shit About", + "You Won't Believe" : "In All Likelihood, You'll Believe", + "You Won’t Believe" : "In All Likelihood, You'll Believe", + "You Won’t Believe" : "In All Likelihood, You'll Believe", + "You Wont Believe" : "In All Likelihood, You'll Believe" + }, + "expressions": { "\\b(?:Top )?((?:(?:\\d+|One|Two|Three|Four|Five|Six|Seven|Eight|Nine|Ten|Eleven|Twelve|Thirteen|Fourteen|Fifteen|Sixteen|Seventeen|Eighteen|Nineteen|Twenty|Thirty|Forty|Fourty|Fifty|Sixty|Seventy|Eighty|Ninety|Hundred)(?: |-)?)+) Things" : "Inane Listicle of $1 Things You've Already Seen Somewhere Else", - "\\b[Rr]estored [Mm]y [Ff]aith [Ii]n [Hh]umanity\\b" : "Affected Me In No Meaningful Way Whatsoever", - "\\b[Rr]estored [Oo]ur [Ff]aith [Ii]n [Hh]umanity\\b" : "Affected Us In No Meaningful Way Whatsoever", - "\\b(?:Top )?((?:(?:\\d+|One|Two|Three|Four|Five|Six|Seven|Eight|Nine|Ten|Eleven|Twelve|Thirteen|Fourteen|Fifteen|Sixteen|Seventeen|Eighteen|Nineteen|Twenty|Thirty|Forty|Fourty|Fifty|Sixty|Seventy|Eighty|Ninety|Hundred)(?: |-)?)+) Weird" : "$1 Boring", - "\\b^(Is|Can|Do|Will) (.*)\\?\\B" : "$1 $2? Maybe, but Most Likely Not.", - "\\b^([Rr]easons\\s|[Ww]hy\\s|[Hh]ow\\s|[Ww]hat\\s[Yy]ou\\s[Ss]hould\\s[Kk]now\\s[Aa]bout\\s)(.*)\\b$":"$2" + "\\b[Rr]estored [Mm]y [Ff]aith [Ii]n [Hh]umanity\\b" : "Affected Me In No Meaningful Way Whatsoever", + "\\b[Rr]estored [Oo]ur [Ff]aith [Ii]n [Hh]umanity\\b" : "Affected Us In No Meaningful Way Whatsoever", + "\\b(?:Top )?((?:(?:\\d+|One|Two|Three|Four|Five|Six|Seven|Eight|Nine|Ten|Eleven|Twelve|Thirteen|Fourteen|Fifteen|Sixteen|Seventeen|Eighteen|Nineteen|Twenty|Thirty|Forty|Fourty|Fifty|Sixty|Seventy|Eighty|Ninety|Hundred)(?: |-)?)+) Weird" : "$1 Boring", + "\\b^(Is|Can|Do|Will) (.*)\\?\\B" : "$1 $2? Maybe, but Most Likely Not.", + "\\b^([Rr]easons\\s|[Ww]hy\\s|[Hh]ow\\s|[Ww]hat\\s[Yy]ou\\s[Ss]hould\\s[Kk]now\\s[Aa]bout\\s)(.*)\\b$":"$2" } }; diff --git a/Source/javascript.vim b/Source/javascript.vim deleted file mode 100644 index 289b7cd..0000000 --- a/Source/javascript.vim +++ /dev/null @@ -1,2 +0,0 @@ -setlocal shiftwidth=4 -setlocal tabstop=4 diff --git a/Source/manifest.json b/Source/manifest.json index 20e97a8..97a3e52 100644 --- a/Source/manifest.json +++ b/Source/manifest.json @@ -6,13 +6,13 @@ "permissions": [ "storage" ], - - "background": + + "background": { - "page": "background.html" + "page": "background.html" }, - - "content_scripts": + + "content_scripts": [ { "matches": ["*://*/*"], @@ -20,21 +20,21 @@ "run_at": "document_end" } ], - - "icons": - { + + "icons": + { "16": "images/icon16.png", - "48": "images/icon48.png", - "128": "images/icon128.png" - }, - - "browser_action": - { - "default_icon": "images/icon19-on.png", + "48": "images/icon48.png", + "128": "images/icon128.png" + }, + + "browser_action": + { + "default_icon": "images/icon19-on.png", "default_title": "Toggle Downworthy" }, - "content_security_policy": "default-src 'none'; script-src 'self'", - "options_page": "options.html" - + "content_security_policy": "default-src 'none'; script-src 'self'", + "options_page": "options.html" + }