🏠 返回首頁 

Greasy Fork is available in English.

Wikipedia: Edit 1st Section [iamMG]

Allow editing the first section of any Wikipedia page


安装此脚本?
  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 #### 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. // ==UserScript==
  7. // @name Wikipedia: Edit 1st Section [iamMG]
  8. // @namespace http://mozilla.status.net/loucypher
  9. // @description Allow editing the first section of any Wikipedia page
  10. // @author LouCypher
  11. // @contributor iamMG (https://greasyfork.org/en/users/155081-iammg)
  12. // @version 3.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. (function() {
  19. var isArticle = getGlobalValue("wgIsArticle");
  20. if (!isArticle) return;
  21. var pageName = getGlobalValue("wgPageName");
  22. var head = document.querySelector("#content > #firstHeading");
  23. var span = head.appendChild(document.createElement("span"));
  24. span.className = "mw-editsection";
  25. span.textContent = "[";
  26. var link = span.appendChild(document.createElement("a"));
  27. link.title = "Edit section: " + head.textContent.replace(/.$/,'');
  28. link.setAttribute("href", "/w/index.php?title=" + pageName + "&action=edit&section=0");
  29. link.textContent = " edit source ";
  30. span.appendChild(document.createTextNode("]"));
  31. //@https://github.com/LouCypher/userscripts/tree/master/getGlobalValue.js
  32. /*
  33. Get value a global variable from user script. Version 1.3
  34. Copyright (C) 2012 LouCypher
  35. This program is free software: you can redistribute it and/or modify
  36. it under the terms of the GNU General Public License as published by
  37. the Free Software Foundation, either version 3 of the License, or
  38. (at your option) any later version.
  39. This program is distributed in the hope that it will be useful,
  40. but WITHOUT ANY WARRANTY; without even the implied warranty of
  41. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  42. GNU General Public License for more details.
  43. You should have received a copy of the GNU General Public License
  44. along with this program. If not, see <http://www.gnu.org/licenses/>
  45. */
  46. /**
  47. * Get the value of a global variable.
  48. *
  49. * @param aGlobalVarName
  50. * String. The name of global variable.
  51. * To get property of a global object, use "object['property']"
  52. * or "object['property1']['property2']".
  53. * @param debug [optional]
  54. * Boolean. If true, display 'variable = value' in console.
  55. * @returns The value of aGlobalVarName.
  56. * If aGlobalVarName is undefined, returns null.
  57. */
  58. function getGlobalValue(aGlobalVarName, debug) {
  59. var script = document.querySelector("head")
  60. .appendChild(document.createElement("script"));
  61. script.type = "text/javascript";
  62. // Unique name for sessionStorage
  63. var itemName = "globalValue_" + (new Date()).getTime().toString();
  64. // Store global value to sessionStorage
  65. script.textContent = "sessionStorage['" + itemName + "'] = " +
  66. "JSON.stringify({'value' : " + aGlobalVarName + "})";
  67. var globalValue;
  68. try {
  69. // Get global value from sessionStorage
  70. globalValue = JSON.parse(sessionStorage[itemName]).value;
  71. } catch (ex) {}
  72. // Clean up
  73. script.parentNode.removeChild(script); // Remove <script> from DOM
  74. sessionStorage.removeItem(itemName); // Remove sessionStorage item
  75. debug && console.log(aGlobalVarName + " = " + globalValue);
  76. return globalValue; // Returns the value of aGlobalVarName
  77. // Returns null if aGlobalVarName is undefined
  78. }
  79. })()