本文来自依云's Blog,转载请注明。
其实自动登录的部分很早就写了的,因为应用于同样的站点,所以就放一起了。
自动登录就不就了,据说是论坛一直就有的 bug。不过现在似乎好了,已经很少遇到需要重新登录的情况。代码展开嘛,是这样子的。Ubuntu 中文论坛支持使用[name]...[/name]
的BBCode来调用 Geshi 插件进行语法高亮。不过高亮的代码却总是收缩起来,只能看到开头几行,要看完整的要么用滚动条,要么点击“展开”链接。Perl 的小骆驼书上有一句话我印象深刻:当程序超过一屏时,bugs 数量会突增。
// ==UserScript== // @name Ubuntu中文论坛自动登录 // @namespace http://lilydjwg.is-programmer.com/ // @description Ubuntu中文论坛自动登录 // @include http://forum.ubuntu.com.cn/ucp.php?mode=login* // @include http://forum.ubuntu.com.cn/viewtopic.php* // @include http://forum.ubuntu.org.cn/ucp.php?mode=login* // @include http://forum.ubuntu.org.cn/viewtopic.php* // ==/UserScript== window.addEventListener("load", function(){ setTimeout(function(){ var links = document.querySelectorAll('a[onfocus]'); if(links){ var evt = document.createEvent("MouseEvents"); evt.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null); for(var i=0, len=links.length; i<len; i++){ if(links[i].innerHTML == '展开'){ links[i].dispatchEvent(evt); } } } if(document.querySelector('input[name=autologin]')){ document.querySelector('input[name=autologin]').checked = true; document.querySelector('input[name=login]').click(); } }, 1000); }, false);