1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/************************************
 * 噗浪表符計數器(書籤版,電腦版和手機網頁版可用)
 *
 * 用法:
 * 1. 將下段javascript儲存成書籤
 * 2. 進入噗浪,先打開表符清單
 * 3. 點擊剛才弄好的書籤
 * 4. 點擊表符組別的圖示,即可在右上角看見表符的組別數量/總數
 *
 ************************************/


javascript:(function(){
	
	var isMobile = document.location.href.includes('/m/');

	function getEmoTotalCount(){
		var total = 0;
		if (isMobile){
			var emos = this.MobileEmoticons.emoticons.custom;
			for (let key in emos){
				if (!isNaN(key)){
					total += emos[key].length;
				}
			}
		}
		else{
			for (let grp of EmoticonCustom.getGroups()){
				total += EmoticonCustom.getEmoticons(grp.id).length;
			}
		}
		return total;
	}

	function addEmoCounterNode(){
		var newNode = document.createElement("DIV");
		newNode.id = "emoCounter";
		var postNode = isMobile ? document.querySelector('#emos_panel .btn.close') : document.querySelector('#emoticon-selector-holder .manager-button');
		postNode.parentNode.insertBefore(newNode, postNode);
		$(newNode).css({
			position : "absolute",
			right: "50px",
			top: "12px",
			lineHeight: "26px"
		});
		return newNode;
	}

	function updateEmoCounterNode(groupType, groupId){
		var counterNode = document.querySelector('#emoCounter');
		if (counterNode == undefined){
			counterNode = addEmoCounterNode();
		}
		var html = '';
		if (groupType == 'custom'){
			if (isMobile){
				html = this.MobileEmoticons.emoticons.custom[groupId].length + '/' + getEmoTotalCount();
			}
			else{
				html = EmoticonCustom.getEmoticons(groupId).length + '/' + getEmoTotalCount();
			}
		}
		else{
			html = getEmoTotalCount();
		}
		$(counterNode).html(html);
	}

	if (isMobile){
		$('#emos_tabs li.tab').on( "click", function() {
			let grpType = $(this).attr('data-type');
			let grpId = $(this).attr('data-g');
			updateEmoCounterNode(grpType, grpId);
		});
	}
	else{
		$('#emoticon-tabs li[emo-group-type]').on( "click", function() {
			let grpType = $(this).attr('emo-group-type');
			let grpId = $(this).attr('emo-group-id');
			updateEmoCounterNode(grpType, grpId);
		});
	}
})()