Last active
August 29, 2015 14:08
-
-
Save ha1t/dd3548f29a141c004fab to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <reference path="../chatwork.d.ts" /> | |
var __extends = this.__extends || function (d, b) { | |
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; | |
function __() { this.constructor = d; } | |
__.prototype = b.prototype; | |
d.prototype = new __(); | |
}; | |
var ChatworkExtension; | |
(function (ChatworkExtension) { | |
// | |
// ここにIExtensionを実装したクラス(実装してなくても)をペコペコ並べると勝手に読み込みます。 | |
// | |
(function (Extensions) { | |
var HelloWorld = (function (_super) { | |
__extends(HelloWorld, _super); | |
function HelloWorld() { | |
_super.apply(this, arguments); | |
} | |
HelloWorld.prototype.onReady = function () { | |
console.log('Hello World Ready!'); | |
}; | |
HelloWorld.prototype.onChatworkReady = function () { | |
console.log('Hello World ChatworkReady!'); | |
}; | |
HelloWorld.prototype.onChatMessageReceived = function (element) { | |
console.log('Hello World ChatMessageReceived!'); | |
}; | |
HelloWorld.prototype.onAvatarsAppear = function (element) { | |
// console.log('Hello World AvatarsAppear!'); | |
}; | |
HelloWorld.prototype.onToListItemAdded = function (element) { | |
// console.log('Hello World ToListItemAdded!'); | |
} | |
HelloWorld.prototype.onGroupAppear = function (element) { | |
console.log('Hello World GroupAppear!'); | |
console.log(element); | |
// rid = element.dataset.rid; | |
}; | |
HelloWorld.metadata = { | |
description: "Hello World" | |
}; | |
return HelloWorld; | |
})(ChatworkExtension.ExtensionBase); | |
Extensions.HelloWorld = HelloWorld; | |
})(ChatworkExtension.Extensions || (ChatworkExtension.Extensions = {})); | |
var Extensions = ChatworkExtension.Extensions; | |
})(ChatworkExtension || (ChatworkExtension = {})); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function createLink(rid) { | |
var onClick = function(e) { | |
var room = RL.rooms[rid]; | |
var view_stat = room.getViewStat(); | |
e.preventDefault(); | |
var params = { | |
cmd: "read", | |
room_id: room.id, | |
mid: room.mid, | |
last_chat_id: view_stat.last_read_id | |
}; | |
CW.get("gateway.php", params, function(response) { | |
room.read_num = response.read_num; | |
room.mention_num = response.mention_num; | |
RL.view.updateUnreadNum(room.id); | |
RL.view.updateSumNumbers(); | |
}); | |
}; | |
var link = document.createElement('A'); | |
link.href = '#'; | |
link.innerText = "[#readall]"; | |
link.addEventListener('click', onClick, false); | |
return link; | |
} | |
if (!window.readChw){ | |
var orgFunc = RL.view.build; | |
RL.view.build = function(a){ | |
orgFunc(a); | |
for (var i=0,l=a.length;i<l;++i){ | |
var bid = a[i]; | |
var link = createLink(bid); | |
var room = RL.rooms[bid]; | |
if(room.getUnreadNum()>0){ | |
var container = $("#_roomListItems").find("[data-rid="+bid+"]")[0]; | |
if(container && container.children[1]){ | |
container.getElementsByClassName('incomplete')[0].appendChild(link); | |
} | |
} | |
} | |
}; | |
window.readChw = true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment