-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathchat-message-length.user.js
114 lines (98 loc) · 4.26 KB
/
chat-message-length.user.js
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
// ==UserScript==
// @author Zaso
// @name IITC plugin: Chat Message Length
// @category Tweaks
// @version 0.1.3.20200216.174028
// @description Counts the chat message characters.
// @id chat-message-length
// @namespace https://github.com/IITC-CE/ingress-intel-total-conversion
// @downloadURL https://github.com/MysticJay/ZasoItems.CE/raw/master/chat-message-length.user.js
// @match https://intel.ingress.com/*
// @grant none
// ==/UserScript==
function wrapper(plugin_info) {
// ensure plugin framework is there, even if iitc is not yet loaded
if(typeof window.plugin !== 'function') window.plugin = function() {};
//PLUGIN AUTHORS: writing a plugin outside of the IITC build environment? if so, delete these lines!!
//(leaving them in place might break the 'About IITC' page or break update checks)
plugin_info.buildName = 'ZasoItems';
plugin_info.dateTimeVersion = '2020-02-16-174028';
plugin_info.pluginId = 'chat-message-length';
//END PLUGIN AUTHORS NOTE
// PLUGIN START ////////////////////////////////////////////////////////
// History
// 0.1.3 Headers changed. Ready for IITC-CE
// 0.1.2 Original sript
// use own namespace for plugin
window.plugin.chatMsgLen = function(){};
window.plugin.chatMsgLen.maxChar = 256;
window.plugin.chatMsgLen.chatLen = 0;
window.plugin.chatMsgLen.getChatLen = function(){
return window.plugin.chatMsgLen.chatLen;
}
window.plugin.chatMsgLen.saveChatLen = function(){
window.plugin.chatMsgLen.chatLen = $('#chattext').val().length;
}
window.plugin.chatMsgLen.checkLimit = function(){
var l = window.plugin.chatMsgLen.getChatLen();
var m = window.plugin.chatMsgLen.maxChar;
if(l > m){
$('#chattext-count').addClass('red');
return 0;
}else{
$('#chattext-count').removeClass('red');
return 1;
}
}
window.plugin.chatMsgLen.updateCount = function(){
window.plugin.chatMsgLen.saveChatLen();
var l = window.plugin.chatMsgLen.getChatLen();
var m = window.plugin.chatMsgLen.maxChar;
$('#chattext-count').text(m-l);
window.plugin.chatMsgLen.checkLimit();
}
window.plugin.chatMsgLen.setupCSS = function(){
$("<style>").prop("type", "text/css").html(''
// +'#chatinput #chattext{width:94%;}'
+'#chatinput.chatMsgLen td.chatMsgLen{display:flex;flex-direction:row;}'
+'#chatinput.chatMsgLen #chattext{flex:1;}'
+'#chatinput.chatMsgLen #chattext-count{color:#aaa;display:inline;padding:0 3px 0 7px;margin:0;line-height:23px;}'
+'#chatinput.chatMsgLen #chattext-count.red{color:#f66;}'
).appendTo("head");
};
window.plugin.chatMsgLen.appendCounter = function(){
$('#chatinput').addClass('chatMsgLen');
$('#chattext').parent('td').addClass('chatMsgLen');
if($('#chattext-count').length < 1){
window.plugin.chatMsgLen.appendContent = '<p id="chattext-count" class="chatMsgLen"></p>';
$('#chattext').after(window.plugin.chatMsgLen.appendContent);
}
}
window.plugin.chatMsgLen.initBind = function(){
$('#chattext').bind('input propertychange', function(){
window.plugin.chatMsgLen.updateCount();
});
//Used 'focus' to update the counter when a player nickname is clicked
$('#chattext').bind('focus', function(){
window.plugin.chatMsgLen.updateCount();
});
}
var setup = function(){
window.plugin.chatMsgLen.setupCSS();
window.plugin.chatMsgLen.appendCounter();
window.plugin.chatMsgLen.initBind();
window.plugin.chatMsgLen.updateCount();
}
// PLUGIN END //////////////////////////////////////////////////////////
setup.info = plugin_info; //add the script info data to the function as a property
if(!window.bootPlugins) window.bootPlugins = [];
window.bootPlugins.push(setup);
// if IITC has already booted, immediately run the 'setup' function
if(window.iitcLoaded && typeof setup === 'function') setup();
} // wrapper end
// inject code into site context
var script = document.createElement('script');
var info = {};
if (typeof GM_info !== 'undefined' && GM_info && GM_info.script) info.script = { version: GM_info.script.version, name: GM_info.script.name, description: GM_info.script.description };
script.appendChild(document.createTextNode('('+ wrapper +')('+JSON.stringify(info)+');'));
(document.body || document.head || document.documentElement).appendChild(script);