| // ==UserScript== | |
| // @name LW Comment Delay | |
| // @namespace http://www.github.com/bakkot | |
| // @description Discourages thoughtless posting on Less Wrong | |
| // @match http://lesswrong.com/lw/* | |
| // @match http://lesswrong.com/r/*/lw/* | |
| // @version 1.1 | |
| // ==/UserScript== | |
| /************************************************** | |
| Tested only on recent versions of Firefox and Chrome. | |
| Installation | |
| ------------ | |
| Save this file as something.user.js. Then: | |
| Firefox users: Install Greasemonkey and open the saved file in Firefox. | |
| Chrome users: Go to chrome://extensions and drag the saved file onto the main body of the window. | |
| Feedback | |
| -------- | |
| bakkot on github or LessWrong | |
| **************************************************/ | |
| var MESSAGE = "In posting this, I am making a good-faith contribution to the collective search for truth."; | |
| // To change the delay, change '4000' below to some other number of milliseconds. | |
| var styleEle = document.createElement('style'); | |
| styleEle.type = 'text/css'; | |
| styleEle.innerHTML = ':disabled { opacity: 0.5; }'; | |
| document.head.appendChild(styleEle); | |
| // OK, so, it's hard to make this accessible to the page, and addEventListener doesn't | |
| // function properly in the context of cloneNode, which LW's JS uses. So... *shudder* this | |
| // gets converted to a string and placed directly. This was the most straightforward | |
| // solution I could find, I swear. | |
| checkChanged = function(checkEle) { | |
| var subButton = checkEle.parentNode.parentNode.querySelector('[type=\'submit\']'); | |
| if(checkEle.checked) { | |
| subButton['data-timer'] = setTimeout(function(subButton){return function(){ | |
| subButton.disabled = false; | |
| };}(subButton), 4000); | |
| } | |
| else { | |
| subButton.disabled = true; | |
| clearTimeout(subButton['data-timer']); | |
| } | |
| }; | |
| var injectHTML = '<label><input type=\'checkbox\' onchange="' + | |
| 'checkChanged = ' + checkChanged.toString() + | |
| ';checkChanged(this)" />' + MESSAGE +'</label>'; | |
| // Top-level comments | |
| if(realcommentButtons=document.querySelector('.realcomment .buttons')) { | |
| realcommentButtons.querySelector('[type=\'submit\']').disabled = true; | |
| realcommentButtons.innerHTML += injectHTML; | |
| } | |
| // Replies | |
| document.getElementById('cancel_').parentNode.innerHTML += injectHTML; | |
| document.getElementById('comment_submit_').disabled = true; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment