Скрипт, разворачивающий все ветки комментариев на странице обсуждений после нажатия на любую ссылку (Expand) [(Развернуть)]. Единственный рабочий из тех, которые я пробовал (пришлось писать самому).
// ==UserScript==
// @author
http://kikovru.livejournal.com/// @name LJ Expand All
// @include
http://*.livejournal.com/*// ==/UserScript==
var expandlink_regex = /
]*>[^<]*<\/A>/g;
function ExpandNext() {
var match = expandlink_regex.exec(document.body.innerHTML);
if (match != null) {
var url = match[1];
var thread_id = url.split('=')[1].split('#')[0];
var anchors = document.body.getElementsByTagName('a');
var the_anchor;
for (var i=0; i < anchors.length; i++) {
if (anchors[i].getAttribute('href') == url) {
the_anchor = anchors[i];
break;
}
}
Expander.make(the_anchor, url, thread_id);
}
}
// thread_expander.js (modificated)
Expander = function(){
this.__caller__; // HTML element from where Expander was called
this.url; // full url of thread to be expanded
this.id; // id of the thread
this.onclick;
this.stored_caller;
this.iframe; // iframe, where the thread will be loaded
this.is_S1; // bool flag, true == journal is in S1, false == in S2
}
Expander.Collection={};
Expander.make = function(el,url,id,is_S1){
var local = (new Expander).set({__caller__:el,url:url.replace(/#.*$/,''),id:id,is_S1:!!is_S1});
local.get();
}
Expander.prototype.set = function(options){
for(var opt in options){
this[opt] = options[opt];
}
return this;
}
Expander.prototype.getCanvas = function(id,context){
return context.document.getElementById('ljcmt'+id);
}
Expander.prototype.parseLJ_cmtinfo = function(context,callback){
var map={}, node, j;
var LJ = context.LJ_cmtinfo;
if(!LJ)return false;
for(j in LJ){
if(/^\d*$/.test(j) && (node = this.getCanvas(j,context))){
map[j] = {info:LJ[j],canvas:node};
if(typeof callback == 'function'){
callback(j,map[j]);
}
}
}
return map;
}
Expander.prototype.loadingStateOn = function(){
this.stored_caller = this.__caller__.cloneNode(true);
this.__caller__.setAttribute('already_clicked','already_clicked');
this.onclick = this.__caller__.onclick;
this.__caller__.onclick = function(){return false;}
this.__caller__.style.color = '#ccc';
}
Expander.prototype.loadingStateOff = function(){
if(this.__caller__){
// actually, the element is removed from main window by
// copying comment from ifame, so this code is not executed (?)
this.__caller__.removeAttribute('already_clicked','already_clicked');
if(this.__caller__.parentNode) this.__caller__.parentNode.replaceChild(this.stored_caller,this.__caller__);
}
var obj = this;
// When frame is removed immediately, IE raises an error sometimes
window.setTimeout(function(){obj.killFrame()},100);
}
Expander.prototype.killFrame = function(){
document.body.removeChild(this.iframe);
ExpandNext();
}
Expander.prototype.isFullComment = function(comment){
return !!Number(comment.info.full);
}
Expander.prototype.killDuplicate = function(comments){
var comment;
var id,id_,el,el_;
for(var j in comments){
if(!/^\d*$/.test(j))continue;
el_ = comments[j].canvas;
id_ = el_.id;
id = id_.replace(/_$/,'');
el = document.getElementById(id);
if(el!=null){
//in case we have a duplicate;
el_.parentNode.removeChild(el_);
}else{
el_.id = id;
window.ContextualPopup && ContextualPopup.searchAndAdd(el_);
window.setupAjax && setupAjax(el_);
window.ESN && ESN.initTrackBtns(el_);
}
}
}
Expander.prototype.getS1width = function(canvas){
//TODO: may be we should should add somie ID to the spacer img instead of searching it
//yet, this works until we have not changed the spacers url = 'dot.gif');
var img, imgs, found;
imgs = canvas.getElementsByTagName('img');
if(!imgs)return false;
for(var j=0;j
');
}else{
// branch for all other browsers
iframe = document.createElement('iframe');
iframe.onload = function(obj){return function(){
obj.onLoadHandler(iframe);
}}(this);
}
iframe.style.height='1px';
iframe.style.width='1px';
iframe.style.display = 'none';
iframe.src = this.url;
document.body.appendChild(iframe);
this.iframe=iframe;
return true;
}
UPD. Забыл написать, надо сохранять в файл с расширением .user.js.