MozTW 討論區 https://forum.moztw.org/ |
|
一個 user script 的問題 https://forum.moztw.org/viewtopic.php?f=13&t=8665 |
第 1 頁 (共 1 頁) |
發表人: | kourge [ 2005-05-29, 12:12 ] |
文章主題 : | 一個 user script 的問題 |
最近正在寫一個 user script,主要的功能,是要重新樣式化 wikipedia:
但是怎麼寫都沒有用 <(o_O)> 我到底是哪裏寫錯了呢?!?! 代碼: // ==UserScript==
// @name Wikipedia Rethemer // @namespace http://kourge.net/ // @description Rethemes wikipedia // @include http://*.wikipedia.org/* // @include *wiki* // ==/UserScript== //remove the original wikipedia monobook stylesheet first (function() { //un-link stylesheets var link = document.getElementByTagName("link"); if (link.type=="text/css"){ link.parentNode.removeChild(link); } //remove <style>s that does style imports var css = document.getElementByTagName("style"); if (css.type=="text/css"){ css.parentNode.removeChild(css); } //remove the long wikipedia words in the title var titlestr = new String(document.title); titlestr.replace(" - Wikipedia, the free encyclopedia", ""); document.title = titlestr; })(); |
發表人: | danielwang [ 2005-05-29, 14:15 ] |
文章主題 : | |
links = document.getElementsByTagName("link"); for (i = links.length - 1; i > 0; i--) { links[i] .... } |
發表人: | danielwang [ 2005-05-29, 14:21 ] |
文章主題 : | |
links = document.getElementsByTagName("link"); for (i = links.length - 1; i > 0; i--) { links[i] .... } |
發表人: | dken [ 2005-05-29, 14:37 ] |
文章主題 : | |
我剛測了一下,也針對你用到的 method 測試了其特性。 底下有個範例: 代碼: <html> <head> <title> test </title> <style type="text/css"> .red {color:red;} </style> </head> <body> <script type="text/javascript"> var css = document.getElementsByTagName("style"); var cssparent = css[0].parentNode; if (css[0].getAttributeNode("type").value == "text/css"){ cssparent.removeChild(css[0]); } </script> <div class="red">測試,這是一串紅色的文字</div> </body> </html> 重點: 1. getElementsByTagName 傳回來的是 list (陣列) 2. 要取得 attribute 的值,要用 value 這個屬性 如此應該就沒問題了吧..... ![]() [/code] |
第 1 頁 (共 1 頁) | 所有顯示的時間為 UTC + 8 小時 |
Powered by phpBB® Forum Software © phpBB Group https://www.phpbb.com/ |