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
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
// ==UserScript==
// @name         噗浪:表符群組增高器
// @namespace    https://www.plurk.com/anonymous
// @version      0.2
// @description  1. 表符選單的群組左箭咀將會化為增高箭咀,輕鬆點擊一覽全部群組
//               2. 表符列表利用箭咀增高減低,輕鬆點擊一覽多個表符
//                  上下箭咀:調整群組高度(顯示3行~7行表符)
//                  CTRL+上下箭咀:自動調整群組表符高度(群組只有5行表符,就顯示5行)
//                  SHIFT+上下箭咀:最大化/最小化群組表符高度(最小官方預設的3行多,最多7行)
// @author       ಠ_ಠ
// @match        https://www.plurk.com/*
// @grant        none
// @run-at      document-idle
// ==/UserScript==

(function() {
    'use strict';

	window.custPlugin = window.custPlugin || {};
	window.custPlugin.emo = window.custPlugin.emo || $();
	window.custPlugin.emo.extend({

		emoHolderRow: 3,

		addEmoHolderExpander: function(){
			var expander = $('#emoHolderExpander');
			if (expander.length){
				return;
			}

			expander = $('<div>', {
				id: "emoHolderExpander",
				css: {
					position : "absolute",
					right: "90px",
					top: "5px",
				}
			});
			var moreRowBtn = $('<div>', {
				text: '▲',
			});
			var lessRowBtn = $('<div>', {
				text: '▼',
			});
			expander.append(moreRowBtn);
			expander.append(lessRowBtn);
			expander.find('> div').css({
				width: '20px',
				height: '16px',
				textAlign: 'center',
				backgroundColor: '#92a0ab',
				color: '#FFF',
				margin: '2px 0',
				borderRadius: '3px',
				cursor: 'pointer',
				userSelect: 'none',
			});

			moreRowBtn.on('click', function(evt){
				if (evt.ctrlKey){
					custPlugin.emo.fixEmoHolderRow();
				}
				else{
					var row = (evt.shiftKey) ? 7 : 1;
					custPlugin.emo.changeEmoHolderRow(row);
				}
			});
			lessRowBtn.on('click', function(evt){
				if (evt.ctrlKey){
					custPlugin.emo.fixEmoHolderRow();
				}
				else{
					var row = (evt.shiftKey) ? -7 : -1;
					custPlugin.emo.changeEmoHolderRow(row);
				}
			});

			expander.find('> div').hover(function(){
				$(this).css('background-color', '#5abfff')
			}, function(){
				$(this).css('background-color', '#92a0ab')
			});


			$('#emoticon-selector-holder .manager-button').after(expander);
		},

		fixEmoHolderRow: function(){
			var needRows = Math.floor(($('#emoticons-holder li').length - 1) / 7 + 1);
			if (this.emoHolderRow == needRows){
				this.emoHolderRow = 3;
			}
			else{
				this.emoHolderRow = needRows;
			}
			this.changeEmoHolderHeight(this.emoHolderRow);
		},

		changeEmoHolderRow: function(i){
			this.emoHolderRow = this.emoHolderRow + i;
			if (this.emoHolderRow > 7){
				this.emoHolderRow = 7;
			}
			else if (this.emoHolderRow < 3){
				this.emoHolderRow = 3;
			}

			this.changeEmoHolderHeight(this.emoHolderRow);
		},

		changeEmoHolderHeight: function(rows){
			if (rows >= 7){
				$('#emoticons-holder').css('height', '384px');
			}
			else if (rows == 6){
				$('#emoticons-holder').css('height', '330px');
			}
			else if (rows == 5){
				$('#emoticons-holder').css('height', '276px');
			}
			else if (rows == 4){
				$('#emoticons-holder').css('height', '222px');
			}
			else{
				$('#emoticons-holder').css('height', '');
			}
		},

		addEmoGroupExpander: function(){
			var leftArrow = $('#emoticon-tabs .tabs-arrow-left');

			if (leftArrow.hasClass('plug-expander')){
				return;
			}
			leftArrow.addClass('plug-expander');

			var emoTabHeight = $('#emoticon-tabs').css('height');
			var emoTabUlWhiteSpace = $('#emoticon-tabs ul').css('white-space');

			leftArrow.hover(function(){
				if ($(this).hasClass("disabled")){
					$(this).removeClass('pif-back');
					$(this).removeClass('disabled');
					$(this).addClass('pif-option');
				}
			}, function(){
				if ($(this).hasClass("pif-option")){
					$(this).removeClass('pif-option');
					$(this).addClass('pif-back');
					$(this).addClass('disabled');
				}
			});

			leftArrow.on('click', function(evt){
				if ($(this).hasClass("pif-option")){
					$(this).removeClass('pif-option');
					$(this).addClass('pif-arrow-up');
					$('#emoticon-tabs').css('height', 'auto');
					$('#emoticon-tabs ul').css('white-space', 'normal');
				}
				else if ($(this).hasClass("pif-arrow-up") && evt.originalEvent !== undefined){
					$(this).removeClass('pif-arrow-up');
					$(this).addClass('pif-option');
					$('#emoticon-tabs').css('height', emoTabHeight);
					$('#emoticon-tabs ul').css('white-space', emoTabUlWhiteSpace);
				}
			});
		},
	});

	new MutationObserver(function (mutations, me) {
		if (document.querySelector('#emoticon-tabs li.current')){
			custPlugin.emo.addEmoGroupExpander();
			custPlugin.emo.addEmoHolderExpander();
			me.disconnect();
		}
	}).observe(document, {childList: true, subtree: true });

})();