Skip to content

Instantly share code, notes, and snippets.

@tony1223
Created May 9, 2011 16:09
Show Gist options
  • Save tony1223/962795 to your computer and use it in GitHub Desktop.
Save tony1223/962795 to your computer and use it in GitHub Desktop.
plurk timeline review
// --{ whole TimeLine jumper (Start)
(function(){
//initial
if(!window.GLOBAL || !window.GLOBAL.page_user) return; //防止render錯頁
if(!window.TimeLine || window.TimeLine.jumper) return; //防止重複定義
//TimeLine Override Functions
TimeLine.getPlurks = function (e, config) {
config = config || {};
var c = TimeLine;
if (c.getting_plurks || c.offset == null) {
if(!config.reGetPlurks) return false; //如果是reGetPlurks,那就一定要get
}
delete config.reGetPlurks;
if(config.jumpTo) {
TimeLine.offset = new Date(config.jumpTo);
delete config.jumpTo;
} if (TimeLine.jumper_reset_offset){
TimeLine.offset = new Date(TimeLine.jumper_reset_offset);
delete TimeLine.jumper_reset_offset;
}
c.getting_plurks = true;
if (c.plurks.length > 0) {
if(config.addToTop){
c.showLoadingBlockAtBegin();
} else {
c.showLoadingBlock();
}
}
var f = function(uid){
return function (h) {
var key = "u"+uid;
var fetched = false;
var hh;
var tryFetchH = function(){
if(--TimeLine.remainCount <= 0){
var minBegin = null;
var maxEnd = null;
h = [];
for(key in TimeLine.receiveBuffer){
userPlurks = TimeLine.receiveBuffer[key];
if(userPlurks.length == 0) continue;
if(config.addToTop && (!minBegin || getFirst(userPlurks).posted.getTime() > minBegin))
minBegin = getFirst(userPlurks).posted.getTime();
else if(!config.addToTop && (!maxEnd || getLast(userPlurks).posted.getTime() > maxEnd))
maxEnd = getLast(userPlurks).posted.getTime();
h = h.concat(userPlurks);
}
delete TimeLine.receiveBuffer;
h.sort(c._sortPlurks);
for(var i = 0; i < h.length-1; i++){
if(h[i].id == h[i+1].id){
h.splice(i--, 1);
}
}
if(h.length != 0){
if(config.addToTop){
for(var i = 0 ; i < h.length; i++){
if(h[i].posted.getTime() <= minBegin){
h.splice(0, i);
break;
};
}
} else {
for(var i = 0 ; i < h.length; i++){
if(h[i].posted.getTime() < maxEnd){
h.splice(i, h.length);
break;
};
}
}
}
fetched = true;
return true;
} else {
return false;
}
};
if (h.error || !TimeLine.receiveBuffer) {
if(h.error == "NoReadPermissionError") {
alert(["河道任意門 通知:\n",
"\t很抱歉,由於 ",SiteState.getUserById(uid).nick_name," 的河道是私密河道\n",
"\t因此河道無法顯示他的噗…"].join(''));
for(var i = 0; i < TimeLine.jumper_user_ids.length; i ++){
if(TimeLine.jumper_user_ids[i]==uid)
TimeLine.jumper_user_ids.splice(i--, 1);
}
if(TimeLine.jumper_user_ids.length==0)
TimeLine.jumper_user_ids.push(SiteState.getPageUser().uid);
}
if(!TimeLine.receiveBuffer) TimeLine.receiveBuffer = {};
TimeLine.receiveBuffer[key] = [];
if(tryFetchH() && h.length != 0){
if (c.plurks.length > 0) {
c.removeLoadingBlock(h);
}
return c._plurksFetched(h);
}
return;
}
if(!fetched){
if(TimeLine.receiveBuffer[key] && TimeLine.receiveBuffer[key].length > 0) {
hh = TimeLine.receiveBuffer[key] = TimeLine.receiveBuffer[key].concat(h); //把之前取得的buffer接上去
} else {
hh = TimeLine.receiveBuffer[key] = h;
}
if(config.addToTop){
if(getLast(hh) && getLast(hh).id > TimeLine.plurks[0].id){ //表示目前取到的plurks沒有和河道接上
TimeLine.offset = config.offset = new Date(getLast(hh).posted.getTime()-1000);
config.reGetPlurks = true;
config.uid = uid;
TimeLine.getPlurks(e, config);
return;
}
for(var i = 0; i < hh.length; i++){
if(hh[i].id <= TimeLine.plurks[0].id){
hh.splice(i--,1);
}
}
if(hh.length == 0){ //沒抓到新的,表示區間內正好沒新的,因為如果已捲到開頭,則TimeLine.notAtBegin必為false
config.uid = uid;
config.offset = TimeLine.setOffsetForward();
if(config.offset.getTime() > (new Date()).getTime()) {
TimeLine.notAtBegin--;
TimeLine.atBeginUid[key] = true;
if(TimeLine.notAtBegin == 0){
c.removeLoadingBlock(h);
TimeLine.getting_plurks = false;
e();
}
} else {
config.reGetPlurks = true;
TimeLine.getPlurks(e, config);
}
return;
}
}
if(tryFetchH() == false) return;
}
if (c.plurks.length > 0) {
c.removeLoadingBlock(h);
}
var j = function () {
c._plurksFetched(h, e);
};
var g = [];
map(h, function (l) {
g.push(l.owner_id);
});
if(c.user_ids || c.private_only || c.responded_only || c.favorite_only || c.notAtBegin || !(window.FB && window.FB.fetchStatusAfterGetPlurks)){
PlurkAdder.fetchUsersIfNeeded(g, j);
} else {
FB.fetchStatusAfterGetPlurks(h, g, j, c);
}
};
};
var sendReq = function(uid, offset){
var d = {
user_id: uid
};
if (offset) {
d.offset = serializeJSON(offset);
}
if (c.user_ids) {
d.user_ids = serializeJSON(c.user_ids);
}
if (c.private_only) {
d.only_private = 1;
}
if (c.favorite_only) {
d.only_favorite = 1;
}
if (c.responded_only) {
d.only_responded = 1;
}
if (TimeLineCache.inCache(d)) {
setTimeout(function () {
return (f(uid))(
TimeLineCache.get(d)
);
}, 30);
return false;
}
var b = loadJSON("/TimeLine/getPlurks");
b.addCallback(function (g) {
if (!g.error) {
TimeLineCache.set(d, g);
}
});
b.addCallback(f(uid));
var a = SiteState.getPageUser();
if (a && a.public_view) {
d.public_view = 1;
}
b.sendReq(d);
};
if(config.uid && config.offset){
sendReq(config.uid, config.offset);
} else {
var t = TimeLine.jumper_user_ids = TimeLine.jumper_user_ids || [SiteState.getPageUser().uid];
var offset = c.offset;
TimeLine.receiveBuffer = {};
TimeLine.remainCount = t.length;
for(var i = 0; i < t.length; i++){
var uid = TimeLine.jumper_user_ids[i];
if(config.addToTop){
if(!TimeLine.atBeginUid["u"+uid]){
sendReq(uid, offset);
} else {
TimeLine.remainCount--;
}
} else {
sendReq(uid, offset);
}
}
}
};
PlurkSearch.showPane = function (c, a, notReload) {
var d = $gc($gp(c, "ul"), "li", "tt_selected");
removeClass(d, "tt_selected");
addClass(c, "tt_selected");
hideElement($bytc(null, "pane"));
showElement($("pane_" + a));
if (a == "search") {
Plurks.removeCurrentOpen();
var b = $("current_query");
$("current_query").focus();
setVisibility($("filter_tab"), false);
if (!PlurkSearch.old_getPlurks) {
PlurkSearch.old_getPlurks = TimeLine.getPlurks
}
TimeLine.getPlurks = PlurkSearch._getPlurks;
if (PlurkSearch.current_query) {
PlurkSearch.query(PlurkSearch.current_query)
} else {
TimeLine.reset();
PlurkSearch.showStartMessage()
}
setVisibility($("updater"), false)
} else {
if (TimeLine.getPlurks != PlurkSearch.old_getPlurks && PlurkSearch.old_getPlurks) {
TimeLine.getPlurks = PlurkSearch.old_getPlurks;
setVisibility($("filter_tab"), true);
if(!notReload){
$bytc("a", "filter_selected")[0].onclick();
}
setVisibility($("updater"), true)
}
}
PlurkSearch.current_pane = a
};
TimeLineCache.cacheKey = function (b) {
var a = [];
if (b.user_id){
a.push(b.user_id);
}
if (b.offset) {
a.push(b.offset)
}
if (b.only_favorite) {
a.push("favorite")
} else {
if (b.only_private) {
a.push("private")
} else {
if (b.only_responded) {
a.push("responded")
} else {
if (b.user_ids) {
a.push("own")
} else {
a.push("all")
}
}
}
}
return a.join("-")
};
Tracks.canBeInserted = function (a, c) {
if(c < 0){
var d = getFirst(a);
try {
var b = absolutePosition(d).x - d.offsetWidth - 20
} catch (f) {
return true
}
if (navigator.userAgent.toLowerCase().indexOf("khtml") != -1) {
b += 25
}
if (b > c) {
return true
}
return false;
} else {
var d = getLast(a);
try {
var b = d.offsetWidth + absolutePosition(d).x + 20
} catch (f) {
return true
}
if (navigator.userAgent.toLowerCase().indexOf("khtml") != -1) {
b += 25
}
if (b < c) {
return true
}
return false;
}
};
TimeLine.scrollBack = function (h) {
var g = TimeLine;
if (InfoOverlay.cloned) {
InfoOverlay.hideInfoOverlay()
}
var d = getFirst(g.active_blocks);
var c = getFirst(g.blocks);
var f = getLast(g.active_blocks);
var e = getLast(g.blocks);
if (d == c && h > 0) {
if (absolutePosition(getBD(d).div_bg).x > 25) {
return false
}
}
if (f == e && h < 0) {
if (absolutePosition(getBD(e).div_bg).x < -50) {
return false
}
}
for (var b = 0; b < g.active_blocks.length; b++) {
var a = g.active_blocks[b];
var j = getBD(a);
if (getBD(a).div_bg) {
a.incLeft(j, h)
}
}
if (g.active_blocks.length > 0) {
g.startChecks(h);
g.endChecks()
}
};
TimeLine.startChecks = function (direction) {
var f = this;
var d, h, g;
var c = f.getCurActive();
d = c[0];
h = c[1];
g = c[2];
if (!h) {
return
}
if ((h.offsetLeft + h.offsetWidth) < this.start_offset) {
if (f.active_blocks.length < 2) {
return true
}
d.removeRender();
f.active_blocks.splice(0, 1)
} else {
if (h.offsetLeft > this.start_offset) {
if (g != 0) {
var e = this.blocks[g - 1];
h = getBD(this.active_blocks[0]).div_bg;
if (e) {
this.active_blocks.splice(0, 0, e);
if (!e.is_rendered) {
e.renderBlock(0, true);
var a = getBD(e).div_bg;
var b = h.offsetLeft - a.offsetWidth;
e.setLeft(b);
e.renderPlurks(true, b);
e.setVisibility(true)
}
}
} else {
if(!Poll.mode && TimeLine.notAtBegin > 0 && direction > 0){ //Poll.mode!=""時,表示目前在檢示新plurk or 新回應;河道開頭尚未讀到 direction > 0 表示是往右捲
setSingleTimeout("getPlurks", function(){
var prev_num_blocks;
var endOffset = new Date(TimeLine.offset);
prev_num_blocks = TimeLine.blocks.length;
TimeLine.offset = new Date(TimeLine.plurks[0].posted);
TimeLine.setOffsetForward();
TimeLine.getPlurks(function(){
TimeLine.blocks = TimeLine.blocks.slice(prev_num_blocks).concat(TimeLine.blocks.slice(0,prev_num_blocks));
delete TimeLine.offset;
TimeLine.offset = new Date(endOffset);
}, {addToTop:true});
}, 300);
}
}
}
}
};
DisplayOptions.selectTab = function (c) {
map($bytc("a", null, $("filter_tab")), function (d) {
if(d.id != "timeline_jumper_tab_btn")
setClass(d, "off_tab");
});
setClass(c, "filter_selected bottom_line_bg");
var b = "all";
var a = c.id;
switch (a) {
case "own_plurks_tab_btn":
b = "own";
break;
case "private_plurks_tab_btn":
b = "private";
break;
case "responded_plurks_tab_btn":
b = "responded";
break;
case "favorite_plurks_tab_btn":
b = "favorite";
break
}
DisplayOptions._setRightMode(b)
};
DisplayOptions.filterTimeline = function (a, b) {
var stillJumper = false;
if($("timeline_jumper_tab_btn").className == "filter_selected"){
TimeLine.saveJumperOffset(false);
}
Plurks.removeCurrentOpen();
this.selectTab(b);
this._filter();
window.scrollTo(0, 0);
return false
};
//TimeLine Jumper Customize Functions
TimeLine.saveJumperOffset = function(forceSave){
if(TimeLine.jumper_reset_offset && !forceSave) return;
var t = TimeLine.getFirstActiveDate();
if(t != null && !isNaN(t.getTime())){
t.setMinutes(t.getMinutes()+2);
TimeLine.jumper_reset_offset = t;
} else if(forceSave){
TimeLine.jumper_reset_offset = new Date();
}
};
TimeLine.setOffsetForward = function(){
var result;
var t = TimeLine.jumper_user_ids;
if((!t || (SiteState.getSessionUser() && ['|',t.join('|'),'|'].join('').indexOf(['|',SiteState.getSessionUser().uid,'|'].join('')) != -1)) && //如果是自己的河道,且在一週內
(new Date()).getTime() - TimeLine.offset.getTime() < 86400000*7 && //且在一周內
(!TimeLine.responded_only && !TimeLine.favorite_only && !TimeLine.private_only)){ //且不為特殊模式下
TimeLine.offset = result = new Date(TimeLine.offset.getTime()+86400000); //往前一天
} else {
TimeLine.offset = result = new Date(TimeLine.offset.getTime()+86400000*7); //否則往前七天
}
return result;
};
SiteState.getUsersNickByIds = function(uids){
var nicknameArray = [];
map(uids, function(uid){
var n;
if(n = SiteState.getUserById(uid).nick_name){
nicknameArray.push(n);
}
});
return nicknameArray;
};
SiteState.getUserByNick = function (b) {
var c = {};
if (!window.FRIENDS) {
return null;
}
if (window.COMPLETION) {
update(c, COMPLETION);
}
update(c, USERS);
update(c, FRIENDS);
var a = map(keys(c), function (e) {
var d = c[e];
if (d.nick_name.toLowerCase() == b.toLowerCase()) {
d.id = d.uid = e;
return d;
}
});
return a;
};
SiteState.getOtherUserByNick = function(nicknameArray, callback){
var nicknameArray_unfetched = nicknameArray.length;
var queryResult = function(nickname){
return function(response){
var match = response.exact_matches;
if(match.length==0){
alert(["喔喔!找不到使用者: ",nickname," 的資料0rz"].join(''));
} else {
for(var i=0; i < match.length; i++){
if(match[i].nick_name.toLowerCase()==nickname.toLowerCase()){
USERS[match[i].id] = match[i];
break;
}
}
if(i==match.length)
alert(["喔喔!找不到使用者: ",nickname," 的資料0rz"].join(''));
}
if(--nicknameArray_unfetched == 0)
callback();
};
};
if(nicknameArray_unfetched == 0){
callback();
} else {
for(var i = 0; i < nicknameArray.length; i++){
if(!SiteState.getUserByNick(nicknameArray[i])){
var b = loadJSON("/Search/queryUsers");
var d = {
q:nicknameArray[i]
};
b.addCallback(queryResult(d.q));
b.sendReq(d);
} else {
if(--nicknameArray_unfetched == 0)
callback();
}
}
}
};
TimeLine.setJumperCache = function(user_ids, toDate){
if(user_ids && toDate){
TimeLine.jumper_cache = {
toDate: TimeLine.dateToJumperFormat(new Date(toDate)),
user_ids: [].concat(user_ids)
}
} else {
TimeLine.jumper_cache = {
toDate: TimeLine.dateToJumperFormat(new Date(TimeLine.getFirstActiveDate() || (new Date()))),
user_ids: [].concat(TimeLine.jumper_user_ids)
};
}
}
TimeLine.jumper_close = function(reFetch){
if(TimeLine.atBeginUid){
delete TimeLine.notAtBegin;
delete TimeLine.jumper_user_ids;
delete TimeLine.atBeginUid;
delete TimeLine.offset;
delete TimeLine.jumper_reset_offset
TimeLine.reset(false);
if(reFetch){
TimeLine.showLoading();
TimeLine.getPlurks();
}
$("timeline_jumper_tab_btn").className = "off_tab";
hideElement($("timeline_jumper_close"));
}
};
TimeLine.jumper = function(user_id, dateObj){
TimeLine.reset(false);
TimeLine.jumper_user_ids = [];
switch (typeof user_id){
case "string": case "number":
TimeLine.jumper_user_ids.push(user_id);
break;
case "object":
TimeLine.jumper_user_ids = [].concat(user_id);
break;
}
TimeLine.notAtBegin = TimeLine.jumper_user_ids.length;
TimeLine.atBeginUid = {};
TimeLine.showLoading();
TimeLine.getPlurks(function(){
$("timeline_jumper_tab_btn").className = "filter_selected";
showElement($("timeline_jumper_close"));
hideElement($("timeline_jumper_tips"));
}, {jumpTo: dateObj});
};
TimeLine.launchJumperByNicks = function(jump_to_users, toDate, onerror){
onerror = onerror || function(){/*noop*/};
var unknown_user = [];
var jump_to_uids = [];
var f;
map(jump_to_users, function(nickname){
if(!nickname.match(/^[a-zA-Z0-9\_\.]+$/)){
alert([nickname, " 不是合法的plurker id"].join(''));
} else if(f = SiteState.getUserByNick(nickname)){
jump_to_uids.push(f.uid);
} else if(SiteState.getSessionUser() && SiteState.getSessionUser().nick_name == nickname){
jump_to_uids.push(SiteState.getSessionUser().uid);
} else {
unknown_user.push(nickname);
}
});
if(unknown_user.length + jump_to_uids.length == 0) return onerror();
TimeLine.showLoadingBlockAtBegin();
SiteState.getOtherUserByNick(unknown_user, function(){
TimeLine.removeLoadingBlock();
map(unknown_user, function(nickname){
var f;
if(f = SiteState.getUserByNick(nickname)){
jump_to_uids.push(f.uid);
}
});
if(jump_to_uids.length > 0 && toDate){
TimeLine.jumper(jump_to_uids, toDate);
} else {
return onerror();
}
});
};
TimeLine.showLoadingBlockAtBegin = function () {
var c = TimeLine;
var b = getFirst(c.active_blocks);
if (b) {
var a = getBD(b).div_bg;
c.loading_div = DIV({
c: "loading_div"
}, c.loading_img);
ACN(a, c.loading_div)
}
};
TimeLine.getFirstActiveDate = function(){
var b = TimeLine.active_blocks;
for(var i = 0; b && i < b.length; i++){
if(b[i].plurks && b[i].plurks[0]){
return b[i].plurks[0].posted;
}
}
return null;
};
TimeLine.dateToJumperFormat = function(t){
var Y = t.getYear()+1900;
var m = t.getMonth()+1; if(m<10) m = "0" + m;
var d = t.getDate(); if(d<10) d = "0" + d;
var H = t.getHours(); if(H<10) H = "0" + H;
var i = t.getMinutes(); if(i<10) i = "0" + i;
var s = t.getSeconds(); if(s<10) s = "0" + s;
var result = [Y,"/",m,"/",d," ",H,":",i,":",s].join('');
if(isNaN(new Date(result).getTime())){
return null;
} else {
return result;
}
};
var jumperTabSpan;
var uniqueArray = function(a){
for(var i = 0; i < a.length -1; i++){
for(var j = i+1; j < a.length; j++){
if(a[i] == a[j]){
a.splice(j--, 1);
}
}
}
};
if(!$("filter_tab") && $("dashboard_holder")){
document.body.insertBefore(UL({id:"filter_tab"}), $("dashboard_holder"));
}
if($("toggle_tab") && $("toggle_tab").getElementsByTagName("li")){
var search_tab_icon = $("toggle_tab").getElementsByTagName("li")[1];
search_tab_icon.onclick = function(){
TimeLine.saveJumperOffset(true);
PlurkSearch.showPane(this, 'search');
};
}
ACN($("filter_tab"), LI({}, A({id:"timeline_jumper_tab_btn", s:"cursor:pointer", c:"off_tab"},
jumperTabSpan = SPAN({}, "河道任意門") ,
SPAN({id:"timeline_jumper_tips", s:"display:none"}, "(", SPAN({ c:"unread_generic"}, "回復"), ")"),
SPAN({id:"timeline_jumper_close", s:"display:none"}, "(", SPAN({ c:"unread_generic"}, "關閉"), ")")
)));
AEV(jumperTabSpan, "click", function(e){
var t = TimeLine.getFirstActiveDate();
t = t || (new Date());
t.setMinutes(t.getMinutes()+2);
var toDate = prompt(["請輸入要跳到河道的哪個時間點?\n",
"\t時間格式範例:2011/05/05 23:09:02\n",
"\t您也可以直接輸入 now 跳到目前的時間點"].join('')
, TimeLine.dateToJumperFormat(t));
if(!toDate) return;
if(toDate == "now"){
toDate = TimeLine.dateToJumperFormat(new Date());
} else {
toDate = TimeLine.dateToJumperFormat(new Date(toDate));
}
var jump_to_users = prompt(["請輸入要跳到哪個人or哪些人的河道?\n",
"\t您可以輸入一至多個id,並用空白字元分開\n",
"\t例如:",SiteState.getPageUser().nick_name," grass7boy\n\n",
"備註:由於當河道捲到七天以前,您的朋友的噗並不會顯示在您的河道上,\n",
"因此您可以透過輸入多個朋友id,一次在河道上顯示他們以前的噗\n",
"(但若您的網路速度較慢,輸入過多id可能會影響河道的顯示速度 ^^~)"].join(''),
SiteState.getUsersNickByIds(TimeLine.jumper_user_ids).join(' '));
if(!jump_to_users) return;
jump_to_users = jump_to_users.split(/[\s]+/);
uniqueArray(jump_to_users);
TimeLine.launchJumperByNicks(jump_to_users, toDate);
});
AEV($("timeline_jumper_close"), "click", function(){
alert("取消河道任意門模式...");
TimeLine.jumper_close(true);
});
AEV($("timeline_jumper_tips"), "click", function(){
var t = TimeLine.jumper_cache;
TimeLine.jumper(t.user_ids, t.toDate);
hideElement($("timeline_jumper_tips"));
});
var timer;
var pure_location = location.href.replace(/#[\d\D]*$/, "");
var hash = null;
setConfig = function(hash){/*noop*/};
if(localStorage){ // localStorage supports
hash = (function(){
var hash = localStorage._gTJhash || null;
var result = null;
if(!hash){
return null;
} else {
var hash = hash.split('|');
for(var i = 0 ; i < hash.length; i++){
var t = hash[i].split('~');
if(pure_location == t[0].split('#')[0]){
result = '#'+t[0].split('#')[1];
hash.splice(i--, 1);
} else if(t[1] && parseInt(t[1]) < (new Date()).getTime()-3600000){
hash.splice(i--, 1);
}
}
}
localStorage._gTJhash = hash.join('|');
return result;
})();
setConfig = function(h){
var hash = localStorage._gTJhash || null;
var saveValue = [pure_location, h, '~', (new Date()).getTime()].join('');
if(!hash){
hash = [saveValue];
} else {
hash = hash.split('|');
for(var i = 0 ; i < hash.length; i++){
var t = hash[i].split('~');
if(pure_location == t[0].split('#')[0]){
hash.splice(i--, 1);
}
}
hash.push(saveValue);
}
localStorage._gTJhash = hash.join('|');
};
}
if(hash){
location.hash = hash;
}
AEV(window, "beforeunload", function(){
clearInterval(timer);
var d = TimeLine.getFirstActiveDate();
if(!d) return;
var now_time = TimeLine.dateToJumperFormat(d);
var uids = TimeLine.jumper_user_ids ;
if(uids && now_time){
var hash = ["#jumper:", uids.join(","),"@", (new Date(now_time)).getTime()].join('');
if(!localStorage){
location.hash = hash;
} else {
setConfig(hash);
}
}
});
var check_hash = function(rightNow){
var h = location.hash.toString();
if(h.indexOf("#jumper:")!=-1){
location.hash = "#";
var uids = h.match(/#jumper:([0-9\,]+)@/) || h.match(/#jumper:([0-9\,]+)$/);
var time = h.match(/#jumper:[^@]*\@([^@]+)$/);
var nicks = h.match(/#jumper:([a-zA-Z0-9\,\_\.]+)/);
if(nicks && !nicks[1].match(/^[0-9\,]+$/)){ //如果只由數字、逗點組成,則表示不為nickname
nicks = nicks[1].split(/[\s]*,[\s]*/);
uniqueArray(nicks);
time = (time && (time[1].match(/^[\d]+$/)?(new Date(parseInt(time[1]))):(new Date(time[1]))) ) || new Date();
TimeLine.launchJumperByNicks(nicks, time);
return;
}
if(time || uids){
uids = (uids && uids[1].split(',')) || [SiteState.getPageUser().uid];
uniqueArray(uids);
time = (time && (time[1].match(/^[\d]+$/)?(new Date(parseInt(time[1]))):(new Date(time[1]))) ) || new Date();
TimeLine.setJumperCache(uids, time);
var t = TimeLine.jumper_cache;
if(rightNow){
var p_tab = $("plurks_pane_li");
if(p_tab && p_tab.className != "tt_selected"){ //in search mode
PlurkSearch.showPane(p_tab, 'plurk', true);
delete TimeLine.jumper_reset_offset; //delete cached reset_offset
}
TimeLine.jumper(t.user_ids, t.toDate);
} else {
showElement($("timeline_jumper_tips"));
}
}
}
delete h;
};
InfoOverlay.menu.addItems(createSeparator());
InfoOverlay.menu.addItems(createItem(DIV("將目前河道變成此Plurker的河道"), $b(function(){
var a = this.user;
if(confirm(["河道任意門 通知:\n",
"\t河道即將顯示 ", a.nick_name, " 的河道內容\n",
"\t您要繼續嗎?"].join(''))){
if($dp.current_div)Plurks._removeExpand(false);
location.hash = ["#jumper:", a.uid, "@", (new Date()).getTime()].join('');
}
}, InfoOverlay)));
InfoOverlay.menu.addItems(createItem(DIV("合併顯示此Plurker的河道"), $b(function(){
var a = this.user;
var len = TimeLine.jumper_user_ids.length;
var nicknameArray = SiteState.getUsersNickByIds(TimeLine.jumper_user_ids.concat([a.uid]));
uniqueArray(nicknameArray);
if(nicknameArray.length == len){
alert("此Plurker的河道已經合併顯示在河道上了...");
return;
}
if(confirm(["河道任意門 通知:\n",
"\t河道即將合併顯示 ", nicknameArray.join(', '), " 的河道\n",
"\t(若您的網路速度較慢,合併顯示過多河道可能會影響河道的顯示速度 ^^~)\n\n",
"\t您要繼續嗎?"].join(''))){
var t = TimeLine.jumper_reset_offset || TimeLine.getFirstActiveDate() || new Date();
t.setMinutes(t.getMinutes()+2);
TimeLine.jumper_user_ids.push(a.uid);
if($dp.current_div)Plurks._removeExpand(false);
location.hash = ["#jumper:", TimeLine.jumper_user_ids.join(','), "@", t.getTime()].join('');
}
}, InfoOverlay)));
InfoOverlay.menu.addItems(createItem(DIV("跳至此Plurker的河道源頭"), $b(function(){
var a = this.user;
var loadScript = function(src, scriptID){
var new_script = document.createElement("script");
new_script.id = scriptID || ("new_script"+(new Date()).getTime());
new_script.src = src;
document.getElementsByTagName("head")[0].appendChild(new_script);
return new_script.id;
};
showElement(this.loading);
hideElement(this.up)
var scriptID = loadScript([
"http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20html%20where%20url%3D%22http%3A%2F%2Fwww.plurk.com%2F",
a.nick_name,
"%22%20and%20xpath%3D'%2F%2F*%2Fdiv%5B%40id%3D%22dash-stats%22%5D%2Ftable%2Ftr%2Ftd'&format=json&callback=InfoOverlay.jumperCallback"
].join(''));
InfoOverlay.jumperCallback = function(response){
showElement(this.up);
hideElement(this.loading)
if(!(td = response.query.results.td)) return;
var since_date = new Date(td[td.length-2].p);
if(!isNaN(since_date.getTime())){
since_date.setDate(since_date.getDate()+7);
if(confirm(["河道任意門 通知:\n",
"\t河道即將跳至 ", a.nick_name, " 剛註冊一週的時間點\n",
"\t也就是:", TimeLine.dateToJumperFormat(since_date),"\n\n",
"\t您要繼續嗎?"].join(''))){
if($dp.current_div)Plurks._removeExpand(false);
location.hash = ["#jumper:", a.uid, "@", since_date.getTime()].join('');
}
} else {
alert([ "取得 ",a.nick_name," 註冊的時間失敗…\n",
"因此這個功能無效0rz..."].join(''));
}
}
}, InfoOverlay)));
InfoOverlay.menu.addItems(createItem(DIV("將河道時間定位到這則噗的發表時間"), $b(function(){
var plurk_elm = this.elm.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode;
var p_obj;
var type;
while(!(p_obj = getPD(plurk_elm))){
plurk_elm = plurk_elm.parentNode;
if(!plurk_elm) break;
}
if(!p_obj) alert("找不到這則噗的資料0rz");
if(p_obj.div.id.match(/m[\d+]/)){
type = "回應";
} else if(p_obj.div.id.match(/p[\d+]/)) {
type = "噗";
}
if(confirm(["河道任意門 通知:\n",
"\t河道即將跳至這則", type, "發表的時間點\n",
"\t也就是:", TimeLine.dateToJumperFormat(p_obj.obj.posted),"\n\n",
"\t您要繼續嗎?"].join(''))){
if($dp.current_div)Plurks._removeExpand(false);
location.hash = ["#jumper:", TimeLine.jumper_user_ids.join(','), "@", p_obj.obj.posted.getTime()].join('');
}
}, InfoOverlay)));
check_hash(false);
timer = setInterval(function(){
check_hash(true);
}, 300);
if(!TimeLine.jumper_user_ids){
TimeLine.jumper_user_ids = [SiteState.getPageUser().uid];
}
})();
// }-- whole TimeLine jumper (End)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment