Wikipedia: Edit 1st Section

Allow editing the first section

  1. /* This program is free software. It comes without any warranty, to
  2. * the extent permitted by applicable law. You can redistribute it
  3. * and/or modify it under the terms of the Do What The Fuck You Want
  4. * To Public License, Version 2, as published by Sam Hocevar. See
  5. * http://sam.zoy.org/wtfpl/COPYING for more details. */
  6.  
  7. // ==UserScript==
  8. // @name Wikipedia: Edit 1st Section
  9. // @namespace http://mozilla.status.net/loucypher
  10. // @description Allow editing the first section
  11. // @author LouCypher
  12. // @version 2.0
  13. // @license WTFPL http://sam.zoy.org/wtfpl/
  14. // @include http://*.wikipedia.org/wiki/*
  15. // @include https://*.wikipedia.org/wiki/*
  16. // @grant none
  17. // ==/UserScript==
  18.  
  19. (function() {
  20. var isArticle = getGlobalValue("wgIsArticle");
  21. if (!isArticle) return;
  22. var pageName = getGlobalValue("wgPageName");
  23. var head = document.querySelector("#content > #firstHeading");
  24.  
  25. var span = head.parentNode.insertBefore(document.createElement("span"),
  26. head);
  27. span.className = "editsection";
  28. span.style.fontSize = "80%";
  29. span.textContent = "[";
  30.  
  31. var link = span.appendChild(document.createElement("a"));
  32. link.title = "Edit section: " + head.textContent;
  33. link.setAttribute("href", "/w/index.php?title=" + pageName +
  34. "&action=edit&section=0");
  35. link.textContent = "edit";
  36.  
  37. span.appendChild(document.createTextNode("]"));
  38.  
  39. //@https://github.com/LouCypher/userscripts/tree/master/getGlobalValue.js
  40. /*
  41. Get value a global variable from user script. Version 1.3
  42. Copyright (C) 2012 LouCypher
  43.  
  44. This program is free software: you can redistribute it and/or modify
  45. it under the terms of the GNU General Public License as published by
  46. the Free Software Foundation, either version 3 of the License, or
  47. (at your option) any later version.
  48.  
  49. This program is distributed in the hope that it will be useful,
  50. but WITHOUT ANY WARRANTY; without even the implied warranty of
  51. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  52. GNU General Public License for more details.
  53.  
  54. You should have received a copy of the GNU General Public License
  55. along with this program. If not, see <http://www.gnu.org/licenses/>
  56. */
  57.  
  58. /**
  59. * Get the value of a global variable.
  60. *
  61. * @param aGlobalVarName
  62. * String. The name of global variable.
  63. * To get property of a global object, use "object['property']"
  64. * or "object['property1']['property2']".
  65. * @param debug [optional]
  66. * Boolean. If true, display 'variable = value' in console.
  67. * @returns The value of aGlobalVarName.
  68. * If aGlobalVarName is undefined, returns null.
  69. */
  70. function getGlobalValue(aGlobalVarName, debug) {
  71. var script = document.querySelector("head")
  72. .appendChild(document.createElement("script"));
  73. script.type = "text/javascript";
  74.  
  75. // Unique name for sessionStorage
  76. var itemName = "globalValue_" + (new Date()).getTime().toString();
  77.  
  78. // Store global value to sessionStorage
  79. script.textContent = "sessionStorage['" + itemName + "'] = " +
  80. "JSON.stringify({'value' : " + aGlobalVarName + "})";
  81.  
  82. var globalValue;
  83. try {
  84. // Get global value from sessionStorage
  85. globalValue = JSON.parse(sessionStorage[itemName]).value;
  86. } catch (ex) {}
  87.  
  88. // Clean up
  89. script.parentNode.removeChild(script); // Remove <script> from DOM
  90. sessionStorage.removeItem(itemName); // Remove sessionStorage item
  91.  
  92. debug && console.log(aGlobalVarName + " = " + globalValue);
  93.  
  94. return globalValue; // Returns the value of aGlobalVarName
  95. // Returns null if aGlobalVarName is undefined
  96. }
  97. })()