├── test.html ├── stop-censorship.php ├── README.md └── stopcensorship.js /test.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dougmartin/Stop-Censorship/HEAD/test.html -------------------------------------------------------------------------------- /stop-censorship.php: -------------------------------------------------------------------------------- 1 | 28 | 29 | You can alternativly include a version hosted on [cdnjs.com][5]: 30 | 31 | 32 | 33 | ## Wordpress Plugin (new) ## 34 | 35 | Christopher Davis created a Wordpress plugin to automatically add the script to your blog. To use it just 36 | unzip the files into a new "stopcensorship" folder in your plugins folder and then activate it in your 37 | Wordpress admin. 38 | 39 | [1]: https://twitter.com/#!/dougmartin 40 | [2]: http://www.opensource.org/licenses/mit-license.php 41 | [3]: http://dougmart.in/stopcensorship/test.html 42 | [4]: https://github.com/dougmartin/Stop-Censorship/zipball/master 43 | [5]: http://cdnjs.com 44 | -------------------------------------------------------------------------------- /stopcensorship.js: -------------------------------------------------------------------------------- 1 | // 2 | // stopcensorship.js 3 | // 4 | // Author: Doug Martin (@dougmartin or http://dougmart.in/) 5 | // 6 | // Usage: Add to head or body of any page to automatically censor the content to protest censorship of the Internet 7 | // 8 | // Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php 9 | // 10 | // NOTE: PLEASE DON'T HOTLINK THIS SCRIPT! 11 | // 12 | 13 | (function () { 14 | var walker, node, root, bar; 15 | 16 | function removeBar() { 17 | // set the no-censor cookie for this session 18 | document.cookie = "__REMOVE_STOP_CENSORSHIP__=1;path=/"; 19 | 20 | // and reload the page 21 | window.location.reload(); 22 | 23 | return false; 24 | } 25 | 26 | function addBar() { 27 | var baseStyles, linkStyles, stopLink, removeLink; 28 | 29 | function createStyledNode(type, text, nodeStyles) { 30 | var i, node, e; 31 | 32 | function applyStyles(styles) { 33 | if (styles) { 34 | for (i in styles) { 35 | if (styles.hasOwnProperty(i)) { 36 | try { 37 | node.style[i] = styles[i]; 38 | } 39 | catch (e) { 40 | } 41 | } 42 | } 43 | } 44 | } 45 | 46 | node = document.createElement(type); 47 | 48 | node.innerHTML = text; 49 | 50 | applyStyles(baseStyles); 51 | applyStyles(nodeStyles); 52 | 53 | return node; 54 | } 55 | 56 | // create the base styles 57 | baseStyles = { 58 | "background": "#000 none repeat scroll 0% 0%", 59 | "borderCollapse": "separate", 60 | "borderSpacing": "0", 61 | "border": "medium none #000", 62 | "bottom": "auto", 63 | "captionSide": "top", 64 | "clear": "none", 65 | "clip": "auto", 66 | "color": "#fff", 67 | "cursor": "auto", 68 | "direction": "ltr", 69 | "display": "inline", 70 | "emptyCells": "show", 71 | "float": "none", 72 | "fontStyle": "normal", 73 | "fontVariant": "normal", 74 | "fontWeight": "bold", 75 | "fontSize": "12px", 76 | "fontFamily": "verdana,helvetica,arial,sans-serif", 77 | "height": "auto", 78 | "left": "auto", 79 | "letterSpacing": "normal", 80 | "lineHeight": "normal", 81 | "listStyle": "disc outside none", 82 | "margin": "0", 83 | "maxHeight": "none", 84 | "maxWidth": "none", 85 | "minHeight": "0", 86 | "minWidth": "0", 87 | "orphans": "2", 88 | "outline": "invert none medium", 89 | "overflow": "visible", 90 | "padding": "0", 91 | "pageBreakAfter": "auto", 92 | "pageBreakBefore": "auto", 93 | "pageBreakInside": "auto", 94 | "position": "static", 95 | "right": "auto", 96 | "tableLayout": "auto", 97 | "textAlign": "left", 98 | "textDecoration": "none", 99 | "textIndent": "0", 100 | "textTransform": "none", 101 | "top": "auto", 102 | "unicodeBidi": "normal", 103 | "verticalAlign": "baseline", 104 | "visibility": "visible", 105 | "whiteSpace": "normal", 106 | "widows": "2", 107 | "width": "auto", 108 | "wordSpacing": "normal", 109 | "zIndex": "auto" 110 | }; 111 | 112 | // and the link styles 113 | linkStyles = { 114 | "textDecoration": "underline", 115 | "cursor": "pointer" 116 | }; 117 | 118 | // add bar to top of page with link to anti-censor site and link to set cookie 119 | bar = createStyledNode("div", "", { 120 | "position": "absolute", 121 | "top": "0", 122 | "left": "0", 123 | "textAlign": "center", 124 | "margin": "0", 125 | "padding": "5px 0", 126 | "width": "100%", 127 | "borderTop": "2px solid #fff", 128 | "borderBottom": "2px solid #fff", 129 | "zIndex": 2147483647 130 | }); 131 | 132 | stopLink = createStyledNode("a", "STOP CENSORSHIP", linkStyles); 133 | stopLink.href = "http://americancensorship.org/"; 134 | 135 | removeLink = createStyledNode("a", "Remove this", linkStyles); 136 | removeLink.href = "#"; 137 | removeLink.onclick = removeBar; 138 | 139 | bar.appendChild(stopLink); 140 | bar.appendChild(createStyledNode("span", "|", { 141 | "padding": "0 10px" 142 | })); 143 | bar.appendChild(removeLink); 144 | 145 | document.body.appendChild(bar); 146 | } 147 | 148 | function run() { 149 | var blackout, blackoutArray; 150 | 151 | function censorNode(node) { 152 | var words, i, j; 153 | 154 | // split contents on whitespace 155 | words = node.nodeValue.split(/\s/); 156 | 157 | // randomly replace words with black bars 158 | for (i = 0, j = words.length; i < j; i++) { 159 | if (Math.random() < 0.5) { 160 | words[i] = blackoutArray.slice(0, words[i].length).join(""); 161 | } 162 | } 163 | 164 | // and rejoin using just space 165 | node.nodeValue = words.join(" "); 166 | } 167 | 168 | // create a big blackout array string to pull from 169 | blackout = String.fromCharCode(0x2588); 170 | blackoutArray = []; 171 | while (blackoutArray.length < 1024) { 172 | blackoutArray.push(blackout); 173 | } 174 | 175 | // process all the text 176 | if (document.createTreeWalker) { 177 | walker = document.createTreeWalker(document.body, NodeFilter.SHOW_TEXT, null, false); 178 | while (walker.nextNode()) { 179 | censorNode(walker.currentNode); 180 | } 181 | } 182 | else { 183 | // do depth first traveral from "Iterative Tree Traversal" at 184 | // http://stackoverflow.com/questions/2579666/getelementsbytagname-equivalent-for-textnodes 185 | root = document.body; 186 | node = root.childNodes[0]; 187 | while (node != null) { 188 | if (node.nodeType == 3) { 189 | censorNode(node); 190 | } 191 | 192 | if (node.hasChildNodes()) { 193 | node = node.firstChild; 194 | } 195 | else { 196 | while (node.nextSibling == null && node != root) { 197 | node = node.parentNode; 198 | } 199 | node = node.nextSibling; 200 | } 201 | } 202 | } 203 | 204 | addBar(); 205 | } 206 | 207 | // adapted from jQuery 208 | function onReady(callback) { 209 | 210 | var isReady = false; 211 | 212 | function ready() { 213 | if (isReady) { 214 | return; 215 | } 216 | 217 | if (!document.body) { 218 | return setTimeout(ready, 1); 219 | } 220 | 221 | isReady = true; 222 | 223 | callback(); 224 | } 225 | 226 | function domContentLoaded() { 227 | if (document.addEventListener) { 228 | document.removeEventListener("DOMContentLoaded", domContentLoaded, false); 229 | ready(); 230 | } 231 | else if (document.attachEvent && (document.readyState === "complete")) { 232 | document.detachEvent("onreadystatechange", domContentLoaded); 233 | ready(); 234 | } 235 | } 236 | 237 | function doScrollCheck() { 238 | if (isReady) { 239 | return; 240 | } 241 | 242 | try { 243 | document.documentElement.doScroll("left"); 244 | } catch (e) { 245 | setTimeout(doScrollCheck, 1); 246 | return; 247 | } 248 | 249 | ready(); 250 | } 251 | 252 | 253 | if (document.addEventListener) { 254 | document.addEventListener("DOMContentLoaded", domContentLoaded, false); 255 | window.addEventListener("load", ready, false); 256 | } 257 | else if (document.attachEvent) { 258 | document.attachEvent("onreadystatechange", domContentLoaded); 259 | window.attachEvent("onload", ready); 260 | 261 | try { 262 | if ((window.frameElement === null) && document.documentElement.doScroll) { 263 | doScrollCheck(); 264 | } 265 | } catch (e) { 266 | } 267 | } 268 | } 269 | 270 | // if undo-censor cookie set, return 271 | if (/__REMOVE_STOP_CENSORSHIP__=1/.test(document.cookie)) { 272 | return; 273 | } 274 | 275 | // wait for document load and then run 276 | if (!document.body) { 277 | onReady(run); 278 | } 279 | else { 280 | run(); 281 | } 282 | 283 | }()); 284 | 285 | 286 | 287 | 288 | 289 | --------------------------------------------------------------------------------