MozTW 討論區

各項 Mozilla 相關軟體與技術討論
現在的時間是 2025-08-23, 05:27

所有顯示的時間為 UTC + 8 小時





發表新文章 回覆主題  [ 4 篇文章 ] 
發表人 內容
文章發表於 : 2005-05-29, 12:12 
離線
[網站管理員]
頭像

註冊時間: 2004-09-27, 09:24
文章: 1685
最近正在寫一個 user script,主要的功能,是要重新樣式化 wikipedia:
  1. 將所有連結的樣式表弄掉
  2. 把標題的 " - Wikipedia, the free encyclopedia" 去掉
  3. 連結自己的樣式表(尚未寫)


但是怎麼寫都沒有用 <(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;

})();

_________________
korp + korp 中文站(沒精神更新)


回頂端
Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-TW; rv:1.7.8) Gecko/20050511 Firefox/1.0.4
 個人資料  
引用回覆  
 文章主題 :
文章發表於 : 2005-05-29, 14:15 
離線
[MozTW 版主群]
頭像

註冊時間: 2003-09-15, 03:47
文章: 1016
來自: Taiwan
links = document.getElementsByTagName("link");
for (i = links.length - 1; i > 0; i--) {
links[i] ....
}


回頂端
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.7) Gecko/20050414
 個人資料  
引用回覆  
 文章主題 :
文章發表於 : 2005-05-29, 14:21 
離線
[MozTW 版主群]
頭像

註冊時間: 2003-09-15, 03:47
文章: 1016
來自: Taiwan
links = document.getElementsByTagName("link");
for (i = links.length - 1; i > 0; i--) {
links[i] ....
}


回頂端
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.7) Gecko/20050414
 個人資料  
引用回覆  
 文章主題 :
文章發表於 : 2005-05-29, 14:37 
離線
[MozTW 版主群]

註冊時間: 2004-08-28, 10:26
文章: 657
我剛測了一下,也針對你用到的 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]

_________________
http://dken.blogspot.com/
圖檔
圖檔


回頂端
Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-TW; rv:1.7.5) Gecko/20041119 Firefox/1.0 (ax)
 個人資料  
引用回覆  
顯示文章 :  排序  
發表新文章 回覆主題  [ 4 篇文章 ] 

所有顯示的時間為 UTC + 8 小時


誰在線上

正在瀏覽這個版面的使用者:沒有註冊會員 和 5 位訪客


不能 在這個版面發表主題
不能 在這個版面回覆主題
不能 在這個版面編輯您的文章
不能 在這個版面刪除您的文章
不能 在這個版面上傳附加檔案

搜尋:
前往 :  
Powered by phpBB® Forum Software © phpBB Group
正體中文語系由 竹貓星球 維護製作
© moztw.org, Mozilla Foundation
MozTW,Mozilla 台灣社群