一个简单的UserJS
Monday, 21. August 2006, 04:59:18
// ==UserScript==
// @name divx.thu.cn filter
// @version 1.00
// @author Returner
// @namespace http://my.opera.com/Returner
// @include http://divx.thu.cn/latest.php*
// ==/UserScript==
/*Changelog:
* 1.00: First version.
*/
function divxcolor() {
var titleColors = { //这些颜色是随便写的,巨丑
internal: '#A08585',
historic: '#A0A585',
screener: '#B0A585',
ts: '#707070',
dummy: '#000000'
};
var blockColors = { //三种类型:none表示不显示标题下面的block,ori表示不改变颜色,#xxxxxx表示用指定颜色显示
//internal: '#ffeeee',
internal: 'none',
historic: 'none',
//screener: 'ori',
screener: 'none',
ts: 'none',
dummy: '#000000'
};
var dTables = document.getElementsByTagName("table");
for (var i = 0, thisTab; thisTab = dTables[i]; i++){
if (thisTab.getAttribute('id') == 'table14'){
var URLText = thisTab.rows[0].cells[0].getElementsByTagName("a")[0].innerText;
var tabType = 'normal';
if(URLText)
if (URLText.match(/\.iNT(ERNAL)?[\.\-]/)){
tabType = 'internal';
} else if (URLText.match(/\.19[0-8][\d][\.\-]/)){ //电影时间年份较早的rlz
tabType = 'historic';
} else if (URLText.match(/\.(DVDSCR)|(screener)[\.\-]/i)){
tabType = 'screener';
} else if (URLText.match(/\.((TS)|(TC)|(CAM)|(TELESYNC))+[\.\-]/i) ){
tabType = 'ts';
}
if (tabType == 'normal'){
thisTab.rows[0].cells[0].setAttribute('background','/images/001.jpg');
} else{
thisTab.rows[0].cells[0].setAttribute('background','');
thisTab.rows[0].cells[0].setAttribute('bgColor',titleColors[tabType]);
thisTab = dTables[++i];
if(blockColors[tabType] == 'none'){
thisTab.innerHTML = '';
} else if(blockColors[tabType] == 'ori'){
} else{
thisTab.rows[0].cells[0].setAttribute('bgColor',blockColors[tabType]);
}
/*thisTab = dTables[++i];
thisTab.setAttribute('bgColor',tagColors.intBlock1);
thisTab.rows[1].cells[0].setAttribute('bgColor',tagColors.intBlock1);*/
}
}
}
}
window.opera.addEventListener('AfterEvent.DOMContentLoaded',
function (ev) {
divxcolor();
},
false);
Notes:
* 在判断ts时,如果正则表达式用/.(TC)|(TS)|(CAM)|(TELESYNC)[.\-]/i,会把标题含有.tsxxxx.之类文本的也判断为真,改成/.((TS)|(TC)|(CAM)|(TELESYNC))+[.\-]/i就OK了。所以前面判断screener的严格来说不太完善
* Opera下不支持thisTab.rows[0].cells[0].background,所以用DOM的方法thisTab.rows[0].cells[0].setAttribute('background','/images/001.jpg')
* 获得单元格中的<A>标签可以用thisTab.rows[0].cells[0].all.tags["a"],Opera也支持,但这里还是用了W3C DOM的标准thisTab.rows[0].cells[0].getElementsByTagName("a")
* 访问一个Object的属性,可以用object.property,也可以用object["property"]。这个程序访问titleColors和blockColors时用的是后者
* 有空一定要多学学DOM的东西,目前为止我还是这方面的白痴……









Anonymous # 21. August 2006, 06:49
strong.....
Returner # 21. August 2006, 06:53