Last active
October 6, 2015 22:58
-
-
Save davereid/3066815 to your computer and use it in GitHub Desktop.
Drupal.org blacklist user script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // ==UserScript== | |
| // @name Drupal.org Blacklist | |
| // @description Helps indicate people on Drupal.org that I have blacklisted from providing help. | |
| // @author Dave Reid | |
| // @version 1.0 | |
| // @include http://drupal.org/* | |
| // @include https://drupal.org/* | |
| // @include http://*.drupal.org/* | |
| // @include https://*.drupal.org/* | |
| // ==/UserScript== | |
| // Content scope runner from dreditor | |
| // If not already running in the page, inject this script into the page. | |
| if (typeof __PAGE_SCOPE_RUN__ == 'undefined') { | |
| // Define a closure/function in the global scope in order to reference the | |
| // function caller (the function that executes the user script itself). | |
| (function page_scope_runner() { | |
| // Retrieve the source of this user script. | |
| var self_src = '(' + page_scope_runner.caller.toString() + ')();'; | |
| // Add the source to a new SCRIPT DOM element; prepend it with the | |
| // __PAGE_SCOPE_RUN__ marker. | |
| // Intentionally no scope-wrapping here. | |
| var script = document.createElement('script'); | |
| script.setAttribute('type', 'text/javascript'); | |
| script.textContent = "var __PAGE_SCOPE_RUN__ = true;\n" + self_src; | |
| // Inject the SCRIPT element into the page. | |
| var head = document.getElementsByTagName('head')[0]; | |
| head.appendChild(script); | |
| })(); | |
| // End execution. This code path is only reached in a GreaseMonkey/user | |
| // script environment. User script environment implementations differ; not all | |
| // browsers (e.g., Opera) understand a return statement here, and it would | |
| // also prevent inclusion of this script in unit tests. Therefore, the entire | |
| // script needs to be wrapped in a condition. | |
| } | |
| // Drupal is undefined when drupal.org is down. | |
| else if (typeof Drupal == 'undefined') { | |
| } | |
| // Execute the script as part of the content page. | |
| else { | |
| // Defines the blacklisted Drupal.org users. | |
| var blacklisted_users = { | |
| 422992 : 'IWasBornToWin', | |
| 25027 : 'dgtlmoon', | |
| 412207 : 'jddeli', | |
| 69670 : 'zoon_unit' | |
| } | |
| String.prototype.beginsWith = function (string) { | |
| return(this.indexOf(string) === 0); | |
| }; | |
| /** | |
| * Define GM_addStyle function if one doesn't exist | |
| */ | |
| if (typeof GM_addStyle != 'function') { | |
| function GM_addStyle(css) { | |
| var style = document.createElement('style'); | |
| style.innerHTML = css; | |
| style.type='text/css'; | |
| document.getElementsByTagName('head')[0].appendChild(style); | |
| } | |
| } | |
| GM_addStyle(' \ | |
| .blacklisted { background-color: #000000; color: #ffffff; font-weight: bold; padding: 1px 6px 2px; margin-left: 0.5em; } \ | |
| '); | |
| for (var uid in blacklisted_users) { | |
| var user_url = '/user/' + uid; | |
| // Add blacklist indicator to any links to the user. | |
| $('a[href="' + user_url + '"]').parent('div.submitted').append('<span class="blacklisted">blacklisted</span>'); | |
| // Add blacklist indicator to the user's page. | |
| if (window.location.pathname.beginsWith(user_url)) { | |
| $('h1#page-title').append('<span class="blacklisted">blacklisted</span>'); | |
| } | |
| } | |
| // End of content scope runner. | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment