Enhanced Ticker

Various fixes for the very bare ticker.

当前为 2017-04-09 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name        Enhanced Ticker
// @namespace   MrBrax, Xelivous
// @description Various fixes for the very bare ticker.
// @include     https://facepunch.com/fp_ticker.php
// @require	https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js
// @version     3.34.1
// @grant 	GM_xmlhttpRequest
// ==/UserScript==

ETICKER = {};

ETICKER.VERSION = 3.34.1;

ETICKER.IMG_MAGNIFIER 	= "iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAAH5SURBVDjLpZK/a5NhEMe/748kRqypmqQQgz/oUPUPECpCoEVwyNStIA6COFR33boIjg6mg4uL0k0EO1RFISKImkHQxlbQRAsx0dgKJm/e53nunnOwViR5leJnuZs+973jHBHB/+D/ah7X2LXWloilyMw5YgtD3CDiBWN4Zno8bQcJHBFBucauZfsolZDCru0OfFcAAUISrLZDfPzSKxuiibOT+T6JCw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ICBteXNxbF9xdWVyeSgpIFs8YSBocmVmPSdmdW5jdGlvbi5teXNxbC1xdWVyeSc+ZnVuY3Rpb24ubXlzcWwtcXVlcnk8L2E+XTogQ2FuJ3QgY29ubmVjdCB0byBsb2NhbCBNeVNRTCBzZXJ2ZXIgdGhyb3VnaCBzb2NrZXQgJy92YXIvcnVuL215c3FsZC9teXNxbGQuc29jaycgKDIpIGluIDxiPi9ob21lL2FqYXhsb2FkL3d3dy9saWJyYWlyaWVzL2NsYXNzLm15c3FsLnBocDwvYj4gb24gbGluZSA8Yj42ODwvYj48YnIgLz4KPGJyIC8+CjxiPldhcm5pbmc8L2I+OiAgbXlzcWxfcXVlcnkoKSBbPGEgaHJlZj0nZnVuY3Rpb24ubXlzcWwtcXVlcnknPmZ1bmN0aW9uLm15c3FsLXF1ZXJ5PC9hPl06IEEgbGluayB0byB0aGUgc2VydmVyIGNvdWxkIG5vdCBiZSBlc3RhYmxpc2hlZCBpbiA8Yj4vaG9tZS9hamF4bG9hZC93d3cvbGlicmFpcmllcy9jbGFzcy5teXNxbC5waHA8L2I+IG9uIGxpbmUgPGI+Njg8L2I+PGJyIC8+Cg=="
ETICKER.IMG_ERROR 		= "https://facepunch.com/fp/ratings/cross.png";
ETICKER.IMG_COMPLETE 	= "https://facepunch.com/fp/ratings/tick.png";

ETICKER.Hide = true;

ETICKER.BanCounter = [];

console.log("[ETicker] Enhanched Ticker v" + ETICKER.VERSION + " loading...");

ETICKER.LOADED = Date.now();

function addGlobalStyle(css) {
	var head, style;
	head = document.getElementsByTagName('head')[0];
	if (!head) { return; }
	style = document.createElement('style');
	style.type = 'text/css';
	style.innerHTML = css;
	head.appendChild(style);
}


function config(){

	// Init global stuff

	// Ratings system
	ratings = {
		
		'tick.png' : 'Agree',
		'cross.png' : 'Disagree',
		'funny2.png' : 'Funny',
		'winner.png' : 'Winner',
		'zing.png' : 'Zing',
		'information.png' : 'Informative',
		'heart.png' : 'Friendly',
		'wrench.png' : 'Useful',
		'rainbow.png' : 'Optimistic',
		'palette.png' : 'Artistic',
		'clock.png' : 'Late',
		'box.png' : 'Dumb',
		
		'lua_king.png' : 'Lua King',
		'lua_helper.png' : 'Lua Helper',
		'weed.png' : 'Smarked',
		'mapping_king.png' : 'Mapping King',
		'moustache.png' : 'Moustache',
		'programming_king.png' : 'Programming King'
		
	}
	var ratings_key = Array();
	for(key in ratings){
		ratings_key.push(key);
	}
	ratings_regex = ratings_key.join("|");

	var cfg = window.localStorage.getItem("ETickerConfig");
	
	if(cfg && cfg.length>5){
		cfg = JSON.parse(cfg);
		if(cfg["validated"] && cfg["weekday"] && cfg["threads"]){
			
			cfg.subforums_name = { // these don't need input from the user
				
				// Facepunch
				6: "General Discussion",
				60: "Fast Threads",
				64: "Videos And Flash Movies and That Kind Of Crap",
				403: "Mass Debate",
				396: "Sensationalist Headlines",
				51: "In The News Node",
				46: "The Gold Members Forum",
				
				// Rust
				415: "Rust General Discussion",
				424: "Rust Experimental Version",
				417: "Rust Servers",
				418: "Rust Modding",
				421: "Rust Bug Reports & Exploits",
				425: "Rust Help & Support",
				
				// Garry's Mod
				15: "Garry's Mod General Discussion",
				198: "Screenshots, Movies, Saves and Dupes",
				66: "Gamemode & Addon Releases",
				65: "Developer Discussion",
				16: "Help & Support",
				
				// Hardware & Software
				397: "Hardware and Software - General Discussion",
				107: "Technical Support",
				243: "PC Building",
				
				// Games
				110: "General Games Discussion",
				339: "Valve/Steam/PowerPlay",
				277: "Team Fortress 2",
				411: "DOTA 2",
				383: "Minecraft",
				189: "Games In Progress",
				
				// Developers
				240: "Programming",
				353: "Web Development",
				38: "Mapping",
				40: "Modelling",

				// Creationism Corner
				75: "Creationism Corner",
				316: "MS Paint",
				315: "Musician's Gig Room",
				389: "Photography",
				76: "Photoshop Contests",
				
				// Hobbies
				262: "Music",
				384: "Automotive Addicts",
				385: "Durgs Discussion",
				393: "Airsoft",
				401: "Urban Exploration",
				361: "Film and Television",
				394: "Witness The Fitness",
				391: "Maker Mates",
				
				// Misc
				33: "Moderators"
				
			};

			var col_mod = "#00aa00";
			var col_staff = "#0070FF";
			var col_fag = "#f0f";
			var col_gold = "#A06000";
			var col_bot = "#48D4DB";

			cfg.bots = [ 
				546131, // pcgamesn
				380954, // bbc
				92596,  // steamgames.com
				55839,  // moddb
				600577, // playrust
			];

			cfg.specialusers = {

				// admins
				garry: 					col_staff,
				gwilty: 				col_staff,
				Robotboy655: 				col_staff,
				Ziks: 					col_staff,
				'Paul.B': 				col_staff,
				Holmzy: 				col_staff,
				Helk: 					col_staff,
				'_Kilburn': 				col_staff,
				layla: 					col_staff,
				Orkel: 					col_staff,
				
				// mods
				'Big Dumb American': 	col_mod,
				Blazyd: 				col_mod,
				Craptasket: 				col_mod,
				GunFox: 				col_mod,
				Gurant: 				col_mod,
				Jaanus: 				col_mod,
				NiandraLades: 				col_mod,
				OvB: 					col_mod,
				postal: 				col_mod,
				rilez: 					col_mod,
				Rusty100: 				col_fag,
				Starpluck: 				col_fag,
				SteveUK: 				col_mod,
				Swebonny: 				col_fag,
				verynicelady: 				col_mod,
				Bradyns:				col_mod,
				Novangel:				col_mod,
				Reagy:					col_mod,
				Kiwi:					col_mod,
				'Sgt Doom':				col_mod,
				Icemaz:					col_mod

				//PCGamesN: 				col_bot,
				//'SteamGames.com': 			col_bot,
				//ModDB: 				col_bot,
				//bbc: 					col_bot

			};

			for(u in cfg.specialusers){
				ETICKER.BanCounter[u] = 0;
			}

			// FPR gold list
			cfg.golds = [
				/*12,47,121,255,401,458,464,467,477,508,632,645,689,708,759,762,802,821,849,918,1077,1190,1349,1510,1664,1682,1779,1917,1946,2006,2100,2101,2202,2361,2442,2536,2577,2731,2843,2860,2917,3060,3425,3448,3475,3500,3731,3807,3855,3895,3916,3918,4077,4082,4116,4173,4187,4201,4214,4560,4654,4776,4878,4890,4993,5017,5052,5133,5144,5217,5323,5384,5521,5558,5571,5573,5586,5589,5679,5775,5853,6084,6100,6300,6457,6469,6490,6522,6546,6641,6676,6765,6855,6922,7090,7115,7258,7439,7488,7499,7513,7808,7814,7928,7930,7963,8048,8049,8141,8170,8524,8553,8582,8702,8707,8806,8813,8873,8909,9100,9177,9200,9273,9296,9298,9312,9477,9588,9656,9677,9757,9908,9910,10061,10063,10200,10225,10239,10268,10652,10760,10777,10896,11470,11478,11623,11812,11934,12030,12042,12196,12377,12910,12953,13064,13155,13315,13505,13579,13596,13692,13760,13944,13994,14331,14628,14913,15462,15476,16289,16337,16351,16392,16560,16849,16928,16980,17104,17205,17229,17267,17476,17543,17557,17622,17829,17995,18212,18431,18568,18756,18846,18855,19122,19155,19199,19268,19408,19431,19605,19807,19845,19929,19975,20017,20049,20268,20340,20689,20694,21315,21447,21604,21630,21942,22083,22167,22429,22450,22512,22705,22804,23000,23175,23355,23738,23751,23898,23922,24633,24947,25373,25633,25644,25701,25741,26272,26294,26452,26548,27049,27070,27396,27399,27448,27885,27974,28503,28539,28618,28785,28930,29270,29390,29567,29632,30071,30384,30560,30566,30874,31086,31229,31259,31552,31702,31729,32058,32102,32313,32481,32610,32653,32815,32848,32993,33032,33077,33275,33343,33427,33572,33624,33647,33772,33840,33851,33890,33953,33979,34082,34416,34805,34849,35106,35274,35296,35514,35575,35648,35906,35950,36089,36124,36208,36248,36251,36293,36452,36668,36730,37388,37601,37642,37749,37943,38046,38091,38108,38600,38952,39543,39571,39603,40179,40194,40226,40290,40291,40400,40495,40556,40573,40652,40656,41049,41516,41628,41859,41992,42175,42242,42326,42340,42388,42408,42613,42666,42774,42827,42907,42999,43014,43590,43744,43804,43805,44007,44164,44458,44483,44516,44687,44755,44814,44904,44980,45141,45293,45493,45637,45654,45855,45957,45967,46037,46157,46187,46189,46390,46531,46664,46847,47011,47213,47291,47535,47561,47596,47940,47951,48009,48133,48155,48213,48239,48244,48301,48461,48474,48526,48539,48591,48616,48736,48845,48972,49284,49330,49346,49396,49458,49461,49613,49731,49768,49820,49991,49999,50174,50187,50204,50249,50273,50415,50482,50587,50641,50813,50916,50923,50926,51052,51233,51381,51459,51462,51486,51605,51644,51699,51759,51785,51798,51938,51989,52015,52050,52240,52374,52384,52467,52470,52537,52569,52629,52743,52980,53008,53030,53052,53097,53101,53222,53369,53400,53407,53409,53501,53662,53812,53906,54007,54082,54172,54257,54467,54481,54557,54583,54637,54658,54689,54725,54751,54860,55061,55518,55810,55877,56097,56133,56236,56318,56396,56411,56439,56575,56590,56675,56832,56850,56855,56948,56950,57024,57165,57220,57447,57728,57737,57951,58055,58132,58223,58228,58239,58390,58460,58489,58539,58675,58763,58793,58915,58997,59008,59412,59435,59505,59523,59562,59621,59736,59862,59965,60000,60040,60205,60215,60231,60236,60262,60270,60385,60422,60474,60475,60510,60570,60654,60673,60763,60825,60856,60904,61021,61071,61209,61235,61329,61551,61679,61693,61731,61824,61844,61865,61889,62004,62018,62055,62098,62137,62153,62159,62171,62308,62446,62466,62561,62566,62634,62651,62765,62918,62996,63039,63088,63150,63187,63277,63281,63354,63473,63524,63793,63803,63804,63823,63975,64028,64046,64064,64084,64379,64415,64552,64719,64725,64750,65000,65161,65182,65200,65258,65305,65315,65380,65386,65403,65509,65545,65644,65668,65691,65791,65969,66050,66166,66183,66194,66331,66405,66471,66496,66562,66771,66878,66891,66979,66985,66998,67063,67081,67138,67161,67196,67414,67567,67812,67842,67908,67935,68064,68083,68128,68372,68486,68654,68718,68771,68882,69131,69149,69160,69258,69287,69318,69335,69395,69438,69480,69615,69685,69704,69750,69793,69802,69907,69963,69977,69991,70002,70004,70085,70172,70295,70374,70466,70479,70491,70603,70673,70740,70855,70871,70948,71037,71095,71120,71122,71195,71292,71495,71587,71590,71593,71670,71674,71705,71884,71917,71954,71971,72068,72094,72150,72201,72321,72457,72658,72846,73039,73129,73160,73173,73207,73273,73485,73672,73685,73775,73866,73928,73959,74015,74064,74115,74147,74184,74337,74339,74347,74424,74462,74507,74514,74565,74591,74595,74636,74672,74822,74914,74997,75004,75218,75387,75452,75511,75660,75829,75874,75912,75918,75955,75973,76063,76326,76364,76430,76483,76653,76745,76827,76869,76983,77020,77083,77258,77286,77321,77440,77465,77476,77603,77705,77801,77919,77956,77997,78094,78149,78224,78228,78257,78276,78316,78344,78349,78356,78495,78670,78723,78809,78898,79144,79265,79290,79388,79392,79425,79439,79459,79620,79774,79793,79794,79822,79942,79950,79981,79982,80048,80101,80107,80109,80248,80383,80390,80403,
				80474,80557,80570,80580,80617,80673,80798,80826,80850,80901,80988,81057,81076,81104,81132,81275,81340,81517,81522,81590,81759,81797,82029,82037,82208,82271,82285,82425,82576,82835,83179,83231,83264,83309,83352,83451,83519,83690,83864,83876,83955,83956,83964,83965,83999,84063,84084,84193,84320,84481,84499,84582,84667,84765,84767,84984,85051,85071,85089,85090,85093,85169,85220,85259,85374,85376,85411,85418,85484,85485,85501,85633,85687,85744,85896,86011,86114,86116,86158,86230,86236,86243,86279,86290,86368,86386,86434,86480,86522,86523,86531,86672,86712,86718,86796,86863,86873,86903,87179,87204,87233,87318,87321,87324,87459,87479,87554,87587,87686,87703,87745,87780,87821,87918,88030,88046,88172,88182,88262,88313,88460,88487,88501,88519,88569,88589,88652,88728,88895,88918,88957,89019,89117,89131,89132,89152,89173,89201,89330,89474,89489,89526,89628,89828,89893,89917,90017,90086,90100,90136,90181,90198,90279,90317,90318,90325,90459,90465,90512,90563,90633,90638,90666,90695,90723,90890,90947,90982,91179,91338,91354,91507,91527,91582,91601,91754,91766,91829,92127,92128,92259,92333,92337,92343,92352,92374,92507,92548,92596,92720,92754,92775,92813,92906,92930,92991,92996,93020,93141,93298,93398,93494,93495,93594,93651,93709,94162,94315,94383,94385,94467,94577,94631,94811,94944,95502,95677,95714,95715,95858,95866,96028,96112,96130,96183,96378,96688,96800,96910,97102,97133,97152,97162,97266,97296,97298,97381,97589,97608,97613,97685,97701,97767,97989,98092,98176,98466,98514,98562,98764,98810,98943,98979,99011,99053,99077,99084,99095,99462,99497,99520,99585,99715,99731,99737,99809,99979,100037,100104,100161,100248,100256,100405,100551,100579,100605,100697,100766,100889,100953,100966,100971,101002,101185,101250,101304,101351,101482,101598,101602,101804,101839,101916,102012,102127,102197,102310,102449,102554,102640,102668,102739,102786,102923,103051,103056,103101,103107,103210,103370,103430,103519,103572,103738,103799,103897,103951,103964,104092,104119,104133,104366,104450,104916,105194,105395,105623,105654,105661,105696,105741,105979,106321,106660,106811,106829,106955,107169,107218,107415,107784,107821,107863,108200,108214,108328,108426,108522,108600,108936,108978,109364,109891,110102,110181,110331,110440,110641,111015,111051,111119,111329,111528,111564,111630,111659,111755,112103,112300,112446,112586,112800,112857,112999,113009,113108,113329,113379,113389,113422,113486,113683,113848,113989,114111,114218,114255,114308,114403,114416,114815,114840,114938,114972,115012,115234,115281,115706,115798,116141,116165,116201,116228,116244,116316,116323,116330,116377,116427,116479,116543,116816,116847,116953,117036,117047,117341,117426,117735,117878,117899,118179,118285,118504,118513,118631,118643,118697,118776,118829,118944,118955,119299,119327,119761,119851,119985,120028,120057,120196,120377,120526,120589,120680,120685,120931,120985,121032,121054,121138,121381,121480,121580,121778,121834,122044,122052,122057,122269,122452,122825,122983,123095,123169,123223,123291,123486,123571,123583,123833,124148,124207,124237,124812,124890,125000,125052,125289,125292,125439,125441,125459,125470,125507,125537,125610,125776,125924,126265,126346,126371,126375,126459,126602,126634,126663,126817,127245,127500,127506,127538,127846,128112,128150,128155,128181,128241,128256,128308,129155,129245,129374,129389,129541,129542,129556,129655,129746,129792,129812,129856,130048,130130,130190,130218,130338,130371,130431,130600,130669,131017,131056,131180,131194,131227,131239,131374,131392,131581,131939,131942,131958,132048,132221,132300,132473,132551,132685,133114,133203,133339,133403,133515,134037,134186,134332,134399,134465,134496,134500,134505,134627,134819,134875,134929,135118,135390,135499,135613,135629,135678,135854,135903,135955,135998,136132,136306,136315,136354,136366,136370,136477,136593,136666,136835,136903,137406,137737,137812,138004,138043,138149,138290,138359,138577,138670,138713,138762,138769,138888,139181,139277,139288,139293,139397,139595,139797,139801,139920,139931,139949,139990,140025,140054,140102,140164,140357,140506,140825,140833,140918,141152,141251,141287,141307,141449,141540,141664,141806,141812,142027,142034,142061,142179,142182,142269,142279,142282,142319,142370,142396,142407,142539,142676,142794,142984,143187,143439,143499,143506,143646,144137,144146,144327,144431,144568,144702,144923,144988,145140,145263,145461,145490,145696,145797,145898,145923,145952,145982,146381,146418,146438,146741,146785,146814,146960,146993,147010,147146,147501,147795,147903,147973,147977,148102,148244,148330,148348,148515,148692,149012,149025,149150,149281,149400,149523,149710,149774,149879,149903,149923,149981,150272,150281,150442,150466,150516,150563,150570,150657,150824,150852,150896,151057,151070,151122,151145,151251,151261,151300,151327,151425,151440,151444,151619,151647,151666,151771,151778,
				151812,151815,151955,151989,152043,152067,152190,152230,152252,152277,152309,152351,152361,152489,152574,152863,153060,153078,153186,153194,153204,153216,153285,153320,153425,153643,153733,153837,153941,153982,153996,154131,154160,154168,154187,154248,154281,154283,154396,154402,154521,154530,154694,154702,154877,154881,154967,155013,155060,155138,155161,155187,155439,155562,155728,155929,155969,155980,156082,156087,156151,156242,156313,156396,156449,156540,156627,156663,156720,156736,156989,157008,157014,157167,157390,157484,157591,157696,157794,157844,157878,157963,158243,158513,158572,158712,158714,158888,158950,158985,159225,159380,159429,159489,159571,159669,159767,159779,159820,159883,159897,159958,160110,160463,160609,160772,160843,160895,161028,161231,161263,161282,161290,161354,161713,161763,161803,161815,161976,161995,162043,162098,162149,162423,162704,162842,163014,163109,163370,163399,163606,163659,163726,163894,164020,164220,164423,164514,164660,164789,164893,165035,165148,165277,165311,165417,165457,165828,165984,166053,166326,166422,166437,166500,166664,166708,166796,166840,167344,167513,167606,167628,167762,167814,167936,167938,168165,168191,168212,168413,168460,168662,168689,168774,168837,168850,168977,169196,169197,169219,169265,169268,169370,169405,170238,170469,170517,170675,170680,171116,171223,171364,171416,171824,172339,172425,172540,173076,173247,173477,173655,173807,173900,173961,174482,174712,174786,174826,174990,175004,175089,175307,175363,175539,175656,175676,175921,176062,176083,176093,176157,176383,176526,176535,176775,177073,177304,177356,177457,177508,177514,177519,177651,177672,177694,177719,177792,177875,178004,178068,178086,178241,178264,178277,178502,178587,178887,178932,179059,179159,179389,179391,179616,179847,179892,179931,180058,180235,180392,180509,180766,180776,180808,180826,180847,180943,181219,181243,181277,181349,181429,181440,181726,181948,181969,181998,182114,182117,182186,182433,182535,182583,182770,182835,182929,183125,183151,183313,183592,183698,183744,183955,184336,184601,184651,184665,184697,184747,184953,185034,185056,185180,185334,185517,185655,185724,185765,185864,186005,186033,186216,186348,186351,186660,186671,186700,186873,187118,187361,187525,187568,187585,187618,187739,187757,187774,187937,187984,188072,188217,188557,188607,188649,188657,188773,189358,189654,189767,189868,190084,190225,190556,190613,190674,190737,190790,190797,190861,191146,191272,191292,191335,191437,191584,191606,191963,192036,192102,192200,192309,192532,192674,192829,192880,193052,193086,193171,193352,193489,193786,194080,194138,194175,194495,194588,195018,195129,195173,196199,196256,196306,196331,196375,196632,196659,196702,196736,196987,197191,197243,197295,197334,197445,197527,197552,197776,197885,197912,197946,198036,198125,198341,198342,198417,198476,198628,198636,198747,199014,199059,199146,199201,199254,199317,199448,199546,199629,199636,199672,199693,199752,199765,199908,199913,199941,199984,200070,200108,200140,200219,200220,200283,200319,200333,200334,200672,200673,200723,200776,200795,200928,200936,201103,201175,201201,201286,201388,201526,201567,201608,201823,202003,202047,202224,202246,202313,202391,202488,202514,202525,202602,202761,202811,202837,202844,203435,203562,203731,203732,203931,204109,204153,205104,205141,205267,205360,205367,205403,205615,205650,205699,205935,206176,206333,206454,206629,206831,206926,207512,207577,207918,208092,208104,208126,208164,208289,208406,208622,208637,208875,208946,208990,209182,209835,209967,210110,210284,210386,210558,210640,210676,210677,210854,210931,211092,211107,211201,211324,211419,211462,211605,211637,211689,211736,211774,211804,211949,212133,212379,212481,212629,212642,212646,212670,212814,212996,213396,213617,213624,213627,213953,214159,214274,214547,214601,214863,215221,215312,215377,215614,215822,216057,216179,216361,216689,216700,216859,216976,216981,217068,217156,217390,217425,217586,217664,218109,218151,218310,218343,218519,218551,218737,218830,218950,219085,219201,219247,219375,219535,219561,219632,219687,219782,219802,220133,220298,220325,220332,220451,220458,220662,220664,220666,220931,221011,221027,221139,221187,221423,221482,221524,221644,221743,221818,221933,221952,222135,222147,222168,222212,222229,222365,222392,222675,222699,222733,222754,222863,223014,223057,223307,223343,223385,223568,223800,223856,223912,223964,224273,224294,224318,224397,224644,224679,224726,224785,224830,224871,225479,225541,225670,225731,225888,226001,226227,226375,226516,226526,226602,226953,227195,227221,227302,227317,227389,227527,227607,227647,227715,227960,227981,228035,228144,228175,228195,228210,228385,228433,228503,228514,228538,228659,228847,228886,228908,228914,229052,229301,229423,229444,229460,229574,229610,229657,229706,229729,229733,229807,229837,230005,230035,
				230089,230100,230198,230253,230422,230436,230491,230525,230568,230619,230652,230687,230780,230883,230946,231072,231193,231212,231237,231301,231602,231631,231644,231773,231881,231913,231997,232435,232583,232831,232857,233100,233276,233325,233471,233630,233766,234025,234053,234162,234273,234285,234300,234324,234343,234492,234617,234652,234717,234783,234788,234886,235064,235118,235154,235227,235325,235373,235677,235811,235864,235917,235941,235942,236041,236056,236077,236135,236138,236149,236381,236419,236450,236876,236889,236963,237341,237455,237518,237589,237666,237675,237686,237722,237795,237800,237827,237868,237892,238010,238264,238266,238298,238490,238525,238553,238641,238649,238761,238827,238898,239046,239086,239499,239515,239657,239679,239774,239862,239935,239945,240152,240264,240302,240628,240664,240713,240727,240810,240843,240905,241024,241057,241125,241137,241218,241287,241334,241507,241549,241563,241672,241731,241801,241899,241918,242118,242236,242243,242332,242336,242352,242460,242656,242738,242836,243053,243104,243114,243279,243502,243762,243892,243903,243999,244050,244091,244142,244195,244367,244382,244448,244462,244675,244899,244917,244936,244946,245077,245079,245161,245288,245487,245489,245568,245681,245703,245704,245787,245971,246142,246143,246209,246393,246793,246947,246991,247002,247126,247140,247166,247198,247477,247606,247686,247691,247718,247955,248058,248320,248595,248611,248633,248644,248645,248646,248664,248667,248733,248824,248827,248899,248931,248993,249151,249265,249311,249495,249540,249587,249603,249680,249719,249935,250141,250173,250215,250295,250330,250337,250433,250611,250646,250698,250744,250839,250861,250902,251041,251072,251089,251257,251377,251436,251448,251713,251776,251976,252016,252046,252100,252165,252211,252226,252280,252363,252430,252457,252517,252805,252846,252888,252930,253031,253313,253349,253381,253387,253429,253444,253594,253713,253903,253916,253930,253932,253975,253990,254198,254256,254430,254490,254512,254690,254700,254707,255068,255100,255149,255177,255328,255395,255514,255526,255634,255719,255908,256195,256543,256651,256670,257004,257019,257051,257086,257149,257238,257256,257370,257427,257471,257577,257589,257680,257738,257767,257784,257828,257913,257952,257968,258063,258151,258181,258322,258381,258413,258609,258809,259150,259310,259445,259597,259666,259839,259948,259979,260166,260169,260259,260400,260872,260888,260960,261064,261081,261409,261473,261647,261706,261744,261756,261830,261905,262000,262048,262860,262879,262887,262908,262938,263073,263581,263821,263992,264085,264550,264736,264748,265023,265037,265339,265831,265854,265873,266124,266176,266232,266465,266589,266743,266852,266887,266981,267066,267182,267537,267613,267678,267930,268005,268083,268193,268224,268663,268687,268706,268848,268937,268961,268984,269012,269114,269170,269322,269377,269487,269515,269575,269609,269746,270053,270103,270223,270296,270812,271242,271404,271533,271655,271886,271940,271956,272035,272073,272108,272697,272853,273243,273603,273883,274477,274535,275208,275324,275348,275504,275524,275634,275786,275838,276730,276815,276825,277004,277027,277138,277224,277330,277521,277528,277560,277619,278128,278191,278270,279209,279451,279473,279789,280093,280424,280451,280568,280652,280704,280729,280907,280930,280967,280995,281149,281204,281539,281559,281634,281663,281765,281871,281956,281963,281975,281977,282066,282144,282280,282291,282304,282335,282485,282637,282715,282772,283154,283237,283334,283899,284315,284408,284453,284518,284727,284754,284809,284960,285018,285483,285500,285649,285880,285895,285921,285965,286086,286095,286125,286493,286558,287083,287150,287252,287293,287611,287695,288009,288166,288631,288859,288947,289337,289417,289456,289460,289470,289600,289618,289739,289750,290291,290426,290648,290738,290753,290896,291049,291236,291255,291360,291465,291820,292004,292180,292290,292526,292871,292907,292984,293118,293237,293788,293790,293850,293874,294141,294144,294197,294311,294324,294662,294814,295011,295599,295683,295804,295823,295907,296417,296483,296838,296895,296927,297011,297194,297452,297532,297569,297864,297931,298026,298216,298387,298401,298407,298469,298916,298919,298989,299172,299431,299523,299985,300157,301181,301209,301540,301541,301543,301614,301847,301912,302068,302390,302772,302906,302922,303157,303359,303496,303689,303999,304116,304127,304262,304360,304444,304778,304795,304982,305091,305282,305307,305403,305607,305626,305713,305745,306164,306254,306346,306464,306545,306643,306710,306750,306885,306988,307184,307190,307293,307384,307615,307826,307863,307917,308016,308339,308465,308696,309128,309186,309207,309212,309321,310100,310315,310461,310603,310711,311238,311247,311471,311819,312107,312123,312174,312181,312599,312684,312824,312828,313119,313187,313354,313403,313515,313715,313749,313860,313934,314025,314104,
				314128,314230,314463,314493,315047,315318,315351,315812,315939,316201,316886,317026,317202,317249,317437,317444,317868,317896,318264,318301,318349,318491,318816,319154,319379,319590,319853,320398,320612,321031,321397,321548,321597,321935,321957,322529,322535,322558,322606,322697,322713,322848,323031,323042,323098,323328,323665,324174,324260,324286,324352,324433,324592,325263,325551,325568,325638,325645,326009,326215,326229,326489,327072,327316,327522,329016,329227,331244,331747,331992,332065,332190,332896,333461,333678,333978,334209,334267,334297,334505,335067,335316,335527,335543,336280,336317,336881,336950,336977,337371,338998,339665,340220,340743,340801,340863,341148,342641,342650,343323,343404,343496,343572,343598,343697,343766,344802,345350,346406,347019,347047,347936,347971,348030,348312,348506,348663,348685,348837,349127,350306,350321,350408,350451,350480,350702,350898,351113,351208,351386,351389,351421,351538,351607,351671,352055,352104,352158,352298,353235,353351,353763,353812,353963,353976,354055,354260,354303,354501,354550,354751,354865,355448,356027,357161,357192,357375,357509,357760,357848,358450,358463,358857,359009,359318,359483,359627,359888,360045,360244,360372,360503,360657,361215,361475,361715,362086,362283,362539,362910,363170,363221,363313,365364,365915,366652,366869,367776,368131,368338,369829,370687,370914,371521,372199,373532,375359,375866,376444,377910,378072,378198,378752,378874,378913,378914,378976,379068,379156,379840,379856,379984,380090,380348,380457,380560,380823,380854,381310,381570,381915,382235,382290,382337,382427,382492,382969,383015,383161,384014,384028,384228,384299,384799,384972,385123,385323,385344,385393,385496,386433,386682,386734,386813,387119,387198,387347,387651,387659,388625,388664,388735,388902,388995,389334,389728,389729,390071,390096,390204,390318,390579,391065,391099,391170,391311,391422,391507,391632,391772,391976,392101,392318,392450,392945,393150,393181,393742,393992,394252,394280,394393,394460,394546,394694,395131,395592,395914,395939,395943,395944,395982,396087,396165,396527,397339,397863,397974,398371,398557,398593,398876,399222,399383,399538,399574,399930,400788,400898,400918,401014,401261,401270,401580,402158,402355,402378,402379,402686,402689,403088,403161,403303,403522,403606,404263,404418,404504,404577,404754,404870,405021,405062,405210,405309,405311,405321,405388,405550,405562,405966,406185,406198,406318,406340,406456,406506,406690,406692,406889,406980,407314,407681,407866,408002,409554,409724,409743,410512,411072,411200,411412,411606,411786,412024,412294,412567,412923,413311,413579,413690,414135,414875,415640,415641,415940,415971,416404,416423,416538,416659,416770,417126,418065,418645,418791,419294,419611,419691,419833,420188,421370,421810,421935,422532,422565,422625,422883,423247,423268,425069,425532,425684,425876,426242,426486,426593,426742,427147,427386,427854,429142,430492,430593,431084,431091,431184,431238,431239,431348,431390,432304,432385,432386,432426,432477,432486,432768,432812,433012,433244,433262,433297,434214,434327,434332,434686,434774,434985,435005,435189,435543,435715,435746,435930,436204,436209,436498,436661,436734,436749,436824,436989,437332,437541,437781,437878,438261,438550,438594,438637,438801,438893,439259,439348,439384,439586,439809,439906,439910,440341,440455,440522,440563,440800,440820,441070,441619,441631,441991,442123,442357,442376,442625,442681,442863,443015,443097,444048,444842,444916,444917,445234,445256,445369,445485,445586,445880,445941,445990,446084,446188,446598,446629,447236,447287,447500,448437,448526,448586,449072,449162,449335,449379,449464,449604,449688,449701,450189,450341,450607,450770,450999,451416,451618,451777,452211,452312,452715,453069,453219,453355,453674,453863,454053,454301,454512,454692,455189,455220,455584,455724,455828,455855,455955,456303,456466,456508,456754,456832,457277,457480,457786,457814,458188,458276,458500,458566,458785,459031,459412,459502,459588,459755,459790,459918,459980,460877,460995,461129,461244,461314,461495,461535,461766,461812,461856,461878,462158,462202,462250,462258,462689,462898,463131,463144,463259,463728,463919,464429,464462,464776,464833,465649,465674,466110,466789,466824,466893,467060,467111,467352,467385,467395,467434,467913,468354,468764,468792,469682,470413,470497,470530,470725,470882,471219,471242,471427,471480,471503,472146,472380,474317,474352,475226,476047,476335,476843,478218,478469,478693,478718,480060,480190,480837,481099,481722,481820,482330,482505,483874,484026,484028,484078,485159,485179,485354,485395,486054,486464,486757,486928,487794,487924,487951,488621,488708,488718,488728,488821,489083,489190,489225,489544,489720,489758,489906,490237,490344,490876,491190,491402,491547,491641,491817,491905,492293,492411,492469,492556,492604,492684,492760,492996,493093,493709,493754,493827,494135,494556,494880,
				495195,495373,495699,495830,495951,496035,496306,496598,496699,496938,497020,498115,498180,499401,500121,500206,500651,500830,501166,501264,502867,502911,503534,503574,503679,503900,504378,504549,504551,504992,505086,505193,505576,505838,505872,506170,506481,507579,507801,507966,508070,508178,508436,508868,509120,509195,509264,509425,509547,509693,509712,510112,510485,510805,510813,510848,510997,511244,511504,511609,511862,511979,512139,512490,513152,513540,513598,513665,514062,514185,514421,514510,515988,516419,517491,518088,518136,518169,518440,518726,518921,519258,520094,520198,522271,522888,523109,523784,523796,524152,525217,526392,526869,527448,528073,530404,532075,532374,533261,533856,534194,534222,534713,535099,535265,535481,535613,537383,537754,538268,538888,539304,539466,539481,539994,540006,540286,540566,540777,540910,542193,542402,542672,543802,544520,545796,546688,547195,548091,548286,549949,550527,550800,551531,552509,552549,553032,553134,553394,553664,553699,553802,553816,553877,553891,553993,554005,554099,554133,554187,554253,554285,554417,554514,554710,554783,554791,555103,555124,555177,555849,555911,555987,556054,556112,556289,556404,556553,556622,556626,556634,556692,556764,556799,556935,557127,557248,557385,557507,557629,557829,557877,558013,558067,558267,558296,558546,558980,559477,562445,562928,563100,564046,564193,565328,566586,575667,576358,577267,577887,578053,579474,580275,580480,580679,582038,582493,582944,584008,584059,584117,585115,585682,587150,588636,588986,589413,589687,590838,590923,591170,595091,595958,598431,599123,600509,600722,603125,604462,607680,607789,611937,612200,612682,612962,613299,620997,621966,622160,626044,629384,630622,633148,633391,643852
			*/];

			// Set new unknown variables
			cfg.show_titlechange = cfg.show_titlechange != undefined ? cfg.show_titlechange : true;
			cfg.show_events = cfg.show_events != undefined ? cfg.show_events : true;
			cfg.show_ratings = cfg.show_ratings != undefined ? cfg.show_ratings : true;
			
			cfg.watch = cfg.watch != undefined ? cfg.watch : Array();

			cfg.notify_mentioned = cfg.notify_mentioned != undefined ? cfg.notify_mentioned : false;
			cfg.notify_watched = cfg.notify_watched != undefined ? cfg.notify_watched : false;
			cfg.notify_rating = cfg.notify_rating != undefined ? cfg.notify_rating : false;
			cfg.notify_modaction = cfg.notify_modaction != undefined ? cfg.notify_modaction : false;
			
			cfg.store_mentioned = cfg.store_mentioned != undefined ? cfg.store_mentioned : true;
			cfg.store_watched = cfg.store_watched != undefined ? cfg.store_watched : false;
			cfg.store_rating = cfg.store_rating != undefined ? cfg.store_rating : false;
			
			cfg.tickerlimit = cfg.tickerlimit != undefined ? cfg.tickerlimit : 100; 

			cfg.darkmode = cfg.darkmode != undefined ? cfg.darkmode : false;
			
			cfg.supersecret = cfg.supersecret != undefined ? cfg.supersecret : "";
			cfg.supersecret_u = cfg.supersecret_u != undefined ? cfg.supersecret_u : "";
			cfg.supersecret_p = cfg.supersecret_p != undefined ? cfg.supersecret_p : "";
			
			return cfg;

		}else{
			alert("Could not validate settings, refresh.");
			Config = {};
			eSaveData();
			return;
		}
	}else{
	
		alert("Resetting settings...");
	
		var def = {
			'validated' : true,
			
			'show_unicode' : true,
			'show_avatars' : true,
			'show_military' : true,
			'show_join'	: false,
			'show_colors' : true,
			'show_titlechange' : true,
			'show_ratings' : true,
			
			'color_readthread' : "#c5c8eb",
			'color_rating' : "#ddf85e",
			'color_highlight': "#f2b2a9",
			'color_hover': "#add4b2",
			
			'notify_mentioned' : true,
			'notify_watched' : true,
			'notify_rating' : true,
			
			'store_mentioned' : true,
			'store_watched' : false,
			'store_rating' : false,
			
			'tickerlimit' : 100,
			
			'subforums': {
				33: true  // moderators
			},
			
			'threads': {
			
			},

			'users' : [],

			'words' : [],
			
			'watch' : {},
		
			'weekday': ["Sunday", "Monday", "Tuesday","Wednesday","Thursday","Friday","Saturday"]
		}
		
		Config = def;
		
		eSaveData();
		
		alert("Settings saved to local storage.");
		
		return def;
	
	}

	
};

Config = config();

ETICKER.USERNAME = $("#navbar-login a").last("strong").text();
Config.specialusers[ETICKER.USERNAME] = "#085d20";

console.log("[ETicker] Got username: " + ETICKER.USERNAME);

// add panel
$("#content_inner").children("div").prepend("<div id='eticker_history'></div>");
//$("#content_inner").children("div").prepend("<br><br><hr><div style='margin:16px 16px 0 16px; text-align:center'></div>");

var panel = $("<div class='eticker_panel'></div>").prependTo(".fp_custom_page");
panel.append("<span style='color:#f070f0'>Enhanced Ticker " + ETICKER.VERSION + "</span>");
$("<img width=16 height=16 id=\"eticker_status\" src=\"" + ETICKER.IMG_LOADING + "\"><br>").appendTo(panel);
$("<button>config</button>").appendTo(panel).click(eConfig);
$("<button>clear ticker</button>").appendTo(panel).click(function(){ eClear(1); });
$("<button>only highlights</button>").appendTo(panel).click(function(){ eClear(2); });
$("<button>only ratings</button>").appendTo(panel).click(function(){ eClear(3); });
$("<button>only read</button>").appendTo(panel).click(function(){ eClear(4); });

if(Config.supersecret && Config.supersecret != "" && Config.supersecret_u && Config.supersecret_u != "" ){
	$("<br><input type='text' placeholder='Username' id='autoreg_username'> <input type='text' placeholder='Hostname' id='autoreg_hostname'> <button id='autoreg_submit'>Create for GMFD</button>").appendTo(panel);
	$("#autoreg_submit").click(function(){
		if(!ETICKER.SuperSecretCache) ETICKER.SuperSecretCache = [];
		var hostname = $("#autoreg_hostname").val();
		var username = $("#autoreg_username").val();
		GM_xmlhttpRequest({
			method: "POST",
			url: Config.supersecret,
			data: "text=REGISTER " + hostname + "&username=" + username,
			headers: {
			  "Authorization": "Basic " + btoa(Config.supersecret_u + ":" + Config.supersecret_p),
			  "Accept": "text/html, application/json",
			  "Content-Type": "application/x-www-form-urlencoded"
			},
			onload: function(data) {
				try {
					var json = JSON.parse(data.responseText);
					
					if(json){
						if(json.error){
							alert("Supersecret error: " + json.error);
							if(json.error.indexOf("already exists") !== -1){
								ETICKER.SuperSecretCache[username] = true;
							}
							return;
						}
						console.log("[Autoreg] Made account for '" + json.username + "' with password '" + json.password +"' on '" + json.hostname + "'.");
						unsafeWindow.eNotify("Autoreg made account for '" + json.username + "' with password '" + json.password +"' on '" + json.hostname + "'.");
						var not = $("<div style='background:#f00;color:#fff;padding:4px'>Supersecret made account for '" + json.username + "' with password '" + json.password +"' on '" + json.hostname + "'.<br><a href='" + json.link +"' target='_blank'>" + json.link + "</a></div>").prependTo("#eticker_history");
						ETICKER.SuperSecretCache[username] = true;
	
						console.log("[Autoreg] Send PM...", data);
						$.post("/private.php?do=insertpm&pmid=", { recipients: username, securitytoken: unsafeWindow.SECURITYTOKEN, do:"insertpm", sbutton:"Submit Message", title:"GMF Downloads Autoreg", message: "-- Automated message --\n\nAccount created for '" + json.hostname + "' with the username '" + json.username + "' and password '" + json.password +"'.\n\n[url=" + json.link +"]" + json.link + "[/url]" }, function(data){
							console.log("[Autoreg] Sent PM.", data);
							not.append("<br><b>PM Sent to user with instructions.</b>");
						}).fail(function(data){
							console.log("[Autoreg] Failed PM.", data);
							not.append("<br><b>PM Failed to send.</b>");
						});

					}else{
						alert("[Autoreg] Got no response at all.");
					}
				}catch(e){
					alert("[Autoreg] JSON error.", data, e);
				}
			},
			onerror: function(data) {
				alert("[Autoreg] error: ", data);
			}
		});
	});
}
//$("<input type='checkbox' id='eticker_hide' checked> Apply hiding for new posts (<span id=\"hiddenposts\"></span>)").appendTo(panel)

function eNotify(text, link){

	console.log("[ETicker] Notify: " + text);

	if( ETICKER.LOADED + 5000 > Date.now() ){ return; }

	if (!("Notification" in window)) {
		alert("[ETicker] This browser does not support desktop notification");
	}else if (Notification.permission === "granted") {
		var notification = new Notification(text);

		if(link != undefined){
			notification.onclick = function(){
				window.open(link);
			}
		}

	}else if (Notification.permission !== 'denied') {
		Notification.requestPermission(function (permission) {
			if (!('permission' in Notification)) {
				Notification.permission = permission;
			}
			if (permission === "granted") {
				var notification = new Notification(text);

				if(link != undefined){
					notification.onclick = function(){
						window.open(link);
					}
				}

			}
		});
	}

	console.log("[ETicker] " + text);
}

function eSaveData(){
	var cfg = Config;
	try {
		window.localStorage.setItem("ETickerConfig", JSON.stringify(cfg));
	} catch(e) {
		if (e == QUOTA_EXCEEDED_ERR) {
			unsafeWindow.eNotify('Quota exceeded!'); //data wasn't successfully saved due to quota exceed so throw an error
			return;
		}
	}
	console.log("[ETicker] Save data...");
	unsafeWindow.eNotify("Settings saved to local storage.");
}

function eConfig(){
	var html = '<div id="eticker_config"><h1 style="font-size:18px">Enhanced Ticker Configuration</h1>';
	
	// Subforums
	html += "<form id='eticker_form' onSubmit='return false;'>";
	
	//html += "<br><br>Separate values with a newline.<br>";

	html += 'Fetched username: ' + ETICKER.USERNAME;
	
	// Print subforums
	html += "<br><br><b>Ignored subforums</b><br>";	
	html += '<div id="eticker_subforums">';
	for(var key in Config.subforums_name){
		html += '<input type="checkbox" data-subid="'+key+'" '+(Config.subforums[key]==true?"checked":"")+'> ' + Config.subforums_name[key] + " (id "+key+")<br>";
	}
	html += '</div>';
	
	// Trigger words
	html += "<br><br><b>Ignored threads</b><br>";
	html += "<select size='10' id='eticker_threads' multiple>";
	for(var k in Config.threads){
		html += '<option value="'+k+'">' + Config.threads[k] + '</option>';
	}
	html += '</select><br><button onclick="$(\'#eticker_threads option:selected\').remove();return false;">Remove</button><br>';
		
	// Watched
	html += "<br><br><b>Watched threads</b><br>";
	html += "<select size='10' id='eticker_watch' multiple>";
	for(var k in Config.watch){
		html += '<option value="'+k+'">' + Config.watch[k] + '</option>';
	}
	html += '</select><br><button onclick="$(\'#eticker_watch option:selected\').remove();return false;">Remove</button><br>';
	
	html += '<br><br><input type="text" id="eticker_tickerlimit" value="' + Config.tickerlimit + '"> Max ticker items before fading out';
	
	html += '<br><br><input type="text" id="eticker_supersecret" value="' + Config.supersecret + '"> GMF Supersecret H';
	html += '<br><br><input type="text" id="eticker_supersecret_u" value="' + Config.supersecret_u + '"> GMF Supersecret U';
	html += '<br><br><input type="text" id="eticker_supersecret_p" value="' + Config.supersecret_p + '"> GMF Supersecret P';
	
	html += '<br><br><input type="checkbox" id="eticker_show_unicode" ' + ( Config.show_unicode ? "checked" : "" ) + '> Show glitched unicode posts';
	html += '<br><input type="checkbox" id="eticker_show_avatars" ' + ( Config.show_avatars ? "checked" : "" ) + '> Show avatars';
	html += '<br><input type="checkbox" id="eticker_show_military" ' + ( Config.show_military ? "checked" : "" ) + '> Show military time';
	html += '<br><input type="checkbox" id="eticker_show_join" ' + ( Config.show_join ? "checked" : "" ) + '> Show joined users';
	html += '<br><input type="checkbox" id="eticker_show_colors" ' + ( Config.show_colors ? "checked" : "" ) + '> Show colored usernames';
	html += '<br><input type="checkbox" id="eticker_show_titlechange" ' + ( Config.show_titlechange ? "checked" : "" ) + '> Show title changes';
	html += '<br><input type="checkbox" id="eticker_show_events" ' + ( Config.show_events ? "checked" : "" ) + '> Show events';
	html += '<br><input type="checkbox" id="eticker_show_ratings" ' + ( Config.show_ratings ? "checked" : "" ) + '> Show ratings';
	html += '<br><input type="checkbox" id="eticker_darkmode" ' + ( Config.darkmode ? "checked" : "" ) + '> Dark mode';
	
	html += '<br><br><input type="checkbox" id="eticker_notify_watched" ' + ( Config.notify_watched ? "checked" : "" ) + '> Notify on watched threads';
	html += '<br><input type="checkbox" id="eticker_notify_rating" ' + ( Config.notify_rating ? "checked" : "" ) + '> Notify on rated posts';
	html += '<br><input type="checkbox" id="eticker_notify_mentioned" ' + ( Config.notify_mentioned ? "checked" : "" ) + '> Notify on mentioned posts';
	html += '<br><input type="checkbox" id="eticker_notify_modaction" ' + ( Config.notify_modaction ? "checked" : "" ) + '> Notify on mod actions';
	
	html += '<br><br><input type="checkbox" id="eticker_store_watched" ' + ( Config.store_watched ? "checked" : "" ) + '> Store watched threads';
	html += '<br><input type="checkbox" id="eticker_store_rating" ' + ( Config.store_rating ? "checked" : "" ) + '> Store rated posts';
	html += '<br><input type="checkbox" id="eticker_store_mentioned" ' + ( Config.store_mentioned ? "checked" : "" ) + '> Store mentioned posts';
	
	html += '<br><br><button class="submit">save settings</button>';
	html += ' <button class="reset">reset settings</button>';
	html += ' <button class="manage" onclick="cfg = prompt(\'Import/Export data here:\', JSON.stringify(Config)); if(cfg){ Config = JSON.parse(cfg); eSaveData(); location.reload(); }">import/export</button>';
	html += ' <button class="close">close</button>';
	
	html += "</form>";
	
	html += "<style>#eticker_form textarea { width:300px; height:150px; }</style>";
	
	html += '</div>';
	$("body").append(html);
}

function eClear(a){
	if(a == 1){
		$("#TickerBox .ticker_item").each(function(){
			$(this).slideUp().remove();
		});
	}
	if(a == 2){
		$("#TickerBox .ticker_item:not(.eticker_highlight)").each(function(){
			$(this).slideUp().remove();
		});
	}
	if(a == 3){
		$("#TickerBox .ticker_item:not(.eticker_rating)").each(function(){
			$(this).slideUp().remove();
		});
	}
	if(a == 4){
		$("#TickerBox .ticker_item:not(.eticker_readthread)").each(function(){
			$(this).slideUp().remove();
		});
	}
}

function eLoadRatings(obj, post_id){
	console.log("[ETicker] Get ratings for post " + post_id);
	$.get('/ajax.php', {'do': 'rate_list', postid: post_id}, function(data){
		var x = $(obj).offset().left;
		var y = $(obj).offset().top + 30;
		var div = $("<div class='top popupbox ratingslist'>" + data.list + "</div>").appendTo("body");
		div.css("left", (x) + "px");
		div.css("top",  (y) + "px");
		div.click(function(){
			$(this).slideUp('fast').remove();
		});
		div.slideDown('fast');
	}, 'json');
}

function eBans(m, a, b){

	if(!Config.notify_modaction) return;
	if($("#bancounter").length == 0) $("<div id='bancounter'></div>").appendTo(".eticker_panel");
	if(!ETICKER.BanCounter[m]) ETICKER.BanCounter[m] = 0;

	ETICKER.BanCounter[m]++;

	var e = $("#bancounter .entry[data-mod='" + m + "']");
	if(e.length > 0){
		$(".count", e).html( ETICKER.BanCounter[m] );
	}else{
		$("<div class='entry' data-mod='" + m + "'><img title='" + m + "' src='https://facepunch.com/image.php?u=" + a + "'><span class='count'>" + ETICKER.BanCounter[m] + "</span>").appendTo("#bancounter");
	}

}

var is_dark_theme = Config.darkmode && Config.darkmode == true; //= $("#logo a").css("margin-left") != "0px";

// add styles
var st =	'.ticker_item  			{ clear:both; overflow:hidden; height:28px; white-space:nowrap } ' +
			'.ticker_item:hover 	{ background-color: ' + ( is_dark_theme ? "#181818" : "#eee" ) + '; }' +
			'.ticker_item a 		{ font-size: 12px !important; ' + ( is_dark_theme ? "color: #ECECEC;" : "" ) + ' } ' +
			'.ticker_item a:hover 	{ ' + ( is_dark_theme ? "color: #FFF !important;" : "" ) + ' } ' +
			'.ticker_item a:visited { ' + ( is_dark_theme ? "color: #AAE !important;" : "" ) + ' } ' +
			'.ticker_item > a:visited { ' + ( is_dark_theme ? "color: #AAE !important;" : "" ) + ' } ' +
			'.eticker_forumlink a:visited { ' + ( is_dark_theme ? "color: #AAE !important;" : "" ) + ' } ' +
			'.ticker_item div > a:visited { ' + ( is_dark_theme ? "color: #AAE !important;" : "" ) + ' } ' +

			'.ticker_item > div { padding:0px !important; } ' +
			'.eticker_forumlink { padding:4px; } ' +
			'.eticker_forumlink a { ' + ( is_dark_theme ? "color: #ccc;" : "" ) + ' } ' +
			'.eticker_threadlink { display:inline-block; max-width:64%; overflow:hidden; height:20px } ' +
			'.eticker_threadlink a { display:inline-block; width:200%; vertical-align:-14px } ' +
			
			'.eticker_event img, .eticker_rating img { vertical-align:-4px !important; } ' +
			'.eticker_icon { margin-left:5px } ' +
			'.eticker_rating .eticker_icon { margin-right:7px } ' +

			'.eticker_time { width:55px !important; line-height:1 !important; } ' +
			
			'.eticker_readthread 	{ background: ' + ( is_dark_theme ? "#303030" : "#c5c8eb" ) + ' !important; } ' +
			'.eticker_rating 		{ background: ' + ( is_dark_theme ? "#3E6536" : "#f3f85e" ) + ' !important; } ' +
			'.eticker_bot 			{ background: ' + ( is_dark_theme ? "#353535" : "#C5D9C6" ) + ' !important; } ' +
			'.eticker_highlight 	{ background: ' + ( is_dark_theme ? "#8F291B" : "#f2b2a9" ) + ' !important; } ' +

			'.eticker_readthread:hover 	{ background: ' + ( is_dark_theme ? "#353535" : "#b2b6de" ) + ' !important; } ' +
			'.eticker_rating:hover 		{ background: ' + ( is_dark_theme ? "#3E6939" : "#dee356" ) + ' !important; } ' +
			'.eticker_bot:hover 		{ background: ' + ( is_dark_theme ? "#393939" : "#BACFBB" ) + ' !important; } ' +
			'.eticker_highlight:hover 	{ background: ' + ( is_dark_theme ? "#8F291F" : "#e59e94" ) + ' !important; } ' +

			'.eticker_event, .eticker_rating { line-height:28px; } ' +
			'.eticker_threadlink, .eticker_forumlink { line-height:20px; } ' + 

			'.eticker_ybox { ' + ( is_dark_theme ? "background: #7E4141;" : "background: #F8FAC0;" ) + ' margin:0 4px; display:inline-block; vertical-align:9px } ' +

			'.eticker_userinfo { width:140px !important; overflow:hidden } ' +
			'.eticker_userinfo a { width:200% !important; } ' +

			'.eticker_panel { padding:5px; margin:15px; background: ' + ( is_dark_theme ? "#353535" : "#eee" ) + '; } ' +
			'.eticker_panel button { font-size:11px; background: ' + ( is_dark_theme ? "#565656" : "#dfdfdf" ) + '; border:none; padding:2px 4px; margin-right:4px; margin-top:5px } ' +
			'.eticker_panel button:hover { background: ' + ( is_dark_theme ? "#595959" : "#ccc" ) + '; cursor:pointer } ' +
			
			'#eticker_history { margin:16px; } ' +
			'hr { height:1px; background:#ccc; border:none; margin: 0 16px } ' +

			'#eticker_config { position:absolute; top:20px; left:20px; background: ' + ( is_dark_theme ? "#222" : "#fff" ) + '; padding:20px; border:5px solid #000; font-size:12px; } ' +
			
			'#postpreview_black { display:none; top:0; left:0; bottom:0; right:0; background:rgba(0,0,0,.6); position:fixed; }' +
			'#postpreview_box { display:none; top:15%; left:10%; right:10%; position:fixed; background:#fff; overflow-x:hidden; max-height:80%; }' +
			
			'.eticker_postbuttons { display:inline-block; float:left; width:95px; } ' +

			'.pbutton { border:none; background-color:rgba(255,255,255,0); background-repeat:no-repeat; background-position: center; width:20px; height:20px; font-size:10px; margin-right:5px; vertical-align:4px; } ' +
			'.pbutton.ig { background-image:url(data:image/png;base64,'+ETICKER.IMG_CROSS+'); }' + // ignore
			'.pbutton.op { background-image:url(data:image/png;base64,'+ETICKER.IMG_PAGE+'); }' + // show op
			'.pbutton.pr { background-image:url(data:image/png;base64,'+ETICKER.IMG_MAGNIFIER+'); }' + // preview
			'.pbutton.wa { background-image:url(data:image/png;base64,'+ETICKER.IMG_STAR+'); margin:0 }' + // watch
			'.pbutton:hover { background-color:#ddd; cursor:pointer; }' +

			'#eticker_status { vertical-align: -3px; margin-left:5px } ' +
			
			'.eticker_avatar { width:20px; height:20px; vertical-align:-6px; margin-right:4px; opacity:.6; background-size:cover; background-align:center center; display:inline-block; } ' +
			'.eticker_avatar:hover { position:absolute; width:80px; height:160px; opacity:1; z-index:999; background-size:auto; background-repeat:no-repeat; background-align:center center; }' +

			'#eticker_form textarea, #eticker_form input[type=text] { padding:2px; background:#fff; border:1px solid #ccc; }' +
			'#eticker_form input[type=checkbox] { vertical-align:-3px; margin:2px 0; } ' +
			'#eticker_form button { padding:5px 10px; } ' +
			'#eticker_subforums { height:150px; overflow-x:hidden; } ' +
			'.eticker_forumlink, .eticker_time, .eticker_userinfo, .eticker_postbuttons, .eticker_threadlink { padding:4px }' +

			'#bancounter { overflow:hidden; margin-top: 5px; } ' +
			'#bancounter .entry { float: left; height: 32px; width: 70px; margin: 0 3px 3px 0; background: rgba(255,0,255,.2); padding: 3px; } ' +
			'#bancounter .count { font-size: 24px; display:inline-block; vertical-align: 9px; font-family: monospace; font-weight: 700; }' +
			'#bancounter img { width:32px; height:32px; margin-right: 7px; } '
;

addGlobalStyle(st);

window.hidden_posts = 0;

function updateposts( num ){
	window.hidden_posts += num;
	//$("#hiddenposts").html( window.hidden_posts );
}

function update_user_colors(){
	$(".eticker_username").each(function(){
		$(this).css("color", Config.specialusers[ $(this).text() ] );
	});
}

// override ticker function completely
function AddTickerPost(post){
	
	var now = new Date();
	var html = post.attributes.getNamedItem( "html" ).value;
	var dt = new Date(post.attributes.getNamedItem( "date" ).value * 1000);
	var dtt = ('0'  + dt.getHours()).slice(-2)+':'+('0' + dt.getMinutes()).slice(-2)+':'+('0' + dt.getSeconds()).slice(-2);
	
	var final_html;

	var hide = false;
	var tclass = "ticker_item";
	var showbtn = true;
	var rating = false;
	var threadname = "Unknown";
	var username = "Unknown";
	var userid = 0;
	var store = false;

	var is_mentioned 	= false;
	var is_self 		= false;
	var is_post 		= true;
	var is_event 		= false;
	var is_join 		= false;
	var is_rating 		= false;
	var is_bot 			= false;
	var is_ban			= false;
	
	var thread_id 		= -1;
	var post_id 		= -1;
	var subforum_id 	= -1;

	var notify_post 	= false;
	var notify_quote 	= false;
	
	// print date
	if(dt.getDate() == now.getDate()){
		dtt += "<br><span style='font-size:8px; color:#999; line-height:1.2em'>Today</span>";
	}else{
		dtt += "<br><span style='font-size:8px; color:#999; line-height:1.2em'>"+Config.weekday[dt.getDay()]+ "</span>";
	}
	
	// check for join messages
	if(html.indexOf("join.png") !== -1 ){ 
		is_post = false; 
		is_event = true; 
		is_join = true; 
		if(!Config.show_join){ updateposts(1); return; }
	}
	
	// check for events
	if(html.indexOf("events.png") !== -1 || html.indexOf("toobig.png") !== -1 || html.indexOf("ddt.png") !== -1 ){ 
		is_post = false; 
		is_event = true;
		if(!Config.show_events){ updateposts(1); return; }
	}
	
	// check for title changes (not even used anymore)
	if(html.indexOf("title.png") !== -1 && !Config.show_titlechange){ updateposts(1); return; }

	// check for ratings
	if(html.indexOf("fp/ratings") !== -1){ is_post = false; is_event = false; is_rating = true; }
	
	// add military time
	if(Config.show_military) html = html.replace(/([0-9:]+)([AP]M)/, dtt );
	
	// outer jquery html, work only with jquery from now on
	var jhtml = $(html);
	
	// add avatar
	if(!is_event && Config.show_avatars){
		var userid = html.match(/\?u=([0-9]+)/);
		if(userid){
			var avatar = $("div:nth-child(3)", jhtml).prepend('<span class="eticker_avatar" style="background-image: url(/image.php?u='+userid[1]+')"></span>');
			avatar.css("background-image", "url(/image.php?u="+userid[1]+")");
			avatar.css("background", "url(/image.php?u="+userid[1]+")");
			if(Config.golds.indexOf(userid[1]) == -1){
				var img = new Image();
				img.src = "/image.php?u=" + userid[1];
				if(img.height > 64) Config.golds.push(userid[1]);
			}
		}
	}
	
	if(is_event) showbtn = false; // don't show buttons on events
	
	$("div", jhtml).css('background',''); // remove all backgrounds
	$("div", jhtml).css('background-color',''); // remove all backgrounds again
	
	$('div[style*="rgb(136, 136, 136)"]', jhtml).addClass("eticker_ybox"); // yellow box thing
	
	$("a", jhtml).each(function(){ // find all links
		
		// hide subforum
		var hpost = $(this).attr("href").match(/f=([0-9]+)/);
		if( hpost && Config.subforums[hpost[1]] && ETICKER.Hide ){
			hide = true;
			updateposts(1);
			return false;
		}
		
		// get username
		if($(this).attr("href").match(/member.php/)){
			// $(this).parent().parent().css("padding", "0px"); // hax
			$(this).addClass('eticker_username');
			username = $(this).text();

			// color usernames
			if( window.global_username == username ){

				$(this).css('color', '#C21780' );
				$(this).css('font-weight','700');
				is_self = true;

			}else if(Config.show_colors && Config.specialusers[username]){

				$(this).css('color',Config.specialusers[username]);
				$(this).css('font-weight','700');

			}

		}

		// get subforum
		var sub_match = $(this).attr("href").match(/forumdisplay\.php\?f=([0-9]+)/);
		if(!is_event && sub_match){
			is_post = true;
			is_rating = false;
			subforum_id = sub_match[1];
			$(this).parent().addClass("eticker_forumlink")
		}

		// get userid
		var user_match = $(this).attr("href").match(/member\.php\?u=([0-9\-]+)/);
		if(user_match){
			userid = user_match[1];

			if(subforum_id > -1) $(this).parent().addClass("eticker_userinfo");

			$(this).attr("title", $(this).text() );

			if( Config.bots.indexOf( parseInt(userid) ) > -1 ){
				$(this).css('color', '#547A56' );
				$(this).css('font-weight','700');
				tclass += " eticker_bot";
			}else if( Config.show_colors && Config.golds.indexOf( parseInt(userid) ) > -1 && !is_self ) {
				$(this).css('color', '#A06000' );
				$(this).css('font-weight','700');
			}

		}		
		
		// get thread name & id
		var thread_match = $(this).attr("href").match(/showthread\.php\?t=([0-9]+)\&p=([0-9]+)/);
		if(!is_event && thread_match){

			thread_link = thread_match[0];
			thread_id = thread_match[1];
			post_id = thread_match[2];
			
			threadname = $(this).text();
			
			if(!is_event && !is_rating){

				$(this).wrap("<div class=\"eticker_threadlink\"></div>");
				$(this).attr("title", $(this).text() );
				
				if( Config.threads[thread_id] && ETICKER.Hide ){
					hide = true;
					updateposts(1);
					return false;
				}
				
				if(subforum_id > -1 && !is_mentioned && Config.watch[thread_id]){
					//final_html = "<div class='ticker_item eticker_highlight' style='background-color: "+Config.color_highlight+"; display: none;'>" + html + "</div>";
					tclass = tclass + " eticker_highlight";
					notify_post = true;
					if(!is_self && Config.notify_watched) unsafeWindow.eNotify("New post in '" + threadname + "' by " + username);
					if(Config.store_watched) store = true;
				}
				
			}
		
		}	
		
	});

	// last read
	var div_lastread = $("div:contains(Last Read)",jhtml);
	if(div_lastread.length > 0){
		div_lastread.addClass("eticker_ybox");
	}

	// events
	//var img_events = $("img[src='/fp/navbar/events.png']",jhtml);
	if(is_event){

		$("img", jhtml).first().addClass("eticker_icon");

		var j_pban = $("img[src='/fp/events/pban.png']", jhtml).length > 0;
		var j_ban = $("img[src='/fp/events/ban.png']", jhtml).length > 0;
		var j_unban = $("img[src='/fp/events/unban.png']", jhtml).length > 0;

		// show banned user, not very useful but eh
		if( j_unban ){
			var mod 		= $(".eticker_username:eq(0)", jhtml).text();
			var unbanned 	= $(".eticker_username:eq(1)", jhtml).text();
			var reason 		= $("b:eq(0)", jhtml).text();
			var t 			= "Woah! " + unbanned + " got unbanned by " + mod + " - “" + reason + "”!";
			if(Config.notify_modaction) unsafeWindow.eNotify(t);
			$(".eticker_username:eq(1)", jhtml).css("color", "");
			Config.specialusers[unbanned] = undefined;
			update_user_colors();
			is_ban = true;
		}else if( j_ban || j_pban ){
			var mod 	= $(".eticker_username:eq(0)", jhtml).text();
			var banned 	= $(".eticker_username:eq(1)", jhtml).text();
			var reason 	= $("b:eq(1)", jhtml).text();
			var t 		= "Bam! " + banned + " got " + ( j_pban ? "perma" : "" ) + "banned by " + mod + " - “" + reason + "”!";
			$(".eticker_username:eq(1)", jhtml).css("color", "#f00");
			if(Config.notify_modaction) unsafeWindow.eNotify(t);
			Config.specialusers[banned] = "#f00";
			update_user_colors();
			is_ban = true;

			eBans(mod, $(".eticker_username:eq(0)", jhtml).attr("href").match(/member\.php\?u=([0-9\-]+)/)[1], banned);

		}

		tclass = "ticker_item eticker_event"

		var div_time = $("div:nth-child(1)",jhtml);
		if(div_time.length > 0){
			div_time.addClass("eticker_time");
		}

	}else if(is_rating){

		$("img", jhtml).first().addClass("eticker_icon");

		tclass = "ticker_item eticker_rating"
		var div_time = $("div:nth-child(1)",jhtml);
		if(div_time.length > 0){
			div_time.addClass("eticker_time");
		}
	}else{

		var div_time = $("div:nth-child(2)",jhtml);
		if(div_time.length > 0){
			div_time.addClass("eticker_time");
		}

	}
	
	// check if mentioned
	var div_quoted = $("div:contains(Quoted)",jhtml);
	var div_mentioned = $("div:contains(Mentioned)",jhtml);
	if(div_quoted.length > 0){
		tclass = "ticker_item eticker_highlight";
		div_quoted.addClass("eticker_ybox");
		if(Config.notify_mentioned) unsafeWindow.eNotify(username + " quoted you in '" + threadname + "'");
		notify_quote = true;
		is_mentioned = true;
		if(Config.store_mentioned) store = true;
	}else if(div_mentioned.length > 0){
		tclass = "ticker_item eticker_highlight";
		div_mentioned.addClass("eticker_ybox");
		if(Config.notify_mentioned) unsafeWindow.eNotify(username + " mentioned you in '" + threadname + "'");
		notify_quote = true;
		is_mentioned = true;
		if(Config.store_mentioned) store = true;
	}	
	
	// fix ratings
	if(is_rating){

		if(!Config.show_ratings){
			updateposts(1);
			return;
		}

		var title = $('a', jhtml).next();
		var val = title.html();
		//tclass = tclass + " eticker_rating";
		
		var rfind = html.match(ratings_regex);
		if(rfind){
			rating = ratings[rfind[0]];
			if(Config.notify_rating) unsafeWindow.eNotify(username + " rated you " + rating + " in '" + (!val ? "(unknown thread)" : threadname ) + "'");
			$("img", jhtml).css('vertical-align','-3px');
		}
		
		if(!val){
			title.html("this thread");
		}else{
			$(jhtml).html(function(){
				return $(this).html().replace("rated your post in", "rated your post <b>" + rating + "</b> in");
			});
			$("<a href='javascript:void(0);' onclick='eLoadRatings(this, " + post_id + ")'>(list)</a>").appendTo(jhtml);
			
		}
		
		if(Config.store_rating) store = true;
	}
	
	// read threads color
	if(html.indexOf("rgba(190, 220") !== -1){
		var div = $('div', jhtml).parent();
		tclass = tclass + " eticker_readthread";
		div.css("background-color", ""); // set background
	}
	
	// preview buttons & ignore
	if(is_post && showbtn){
		var holder = $("<div class='eticker_postbuttons'></div>").insertAfter( $(jhtml).find(".eticker_userinfo") );
		$("<button title='Watch thread' class='pbutton wa'></button>").prependTo(holder);
		$("<button title='Add to ignore list' class='pbutton ig'></button>").prependTo(holder);
		$("<button title='Preview post' class='pbutton pr'></button>").prependTo(holder);
		$("<button title='Preview OP' class='pbutton op'></button>").prependTo(holder);
	}

	// merge html
	if(!jhtml[0]){
		console.log("[ETicker] No JHTML");
	}else{
		html = jhtml[0].outerHTML;
	}
	
	// set final html if not set
	
	if(!final_html && !hide) final_html = "<div class='" + tclass + "' style=''>" + html + "</div>";
	
	var item = $( final_html ).prependTo( '#TickerBox' );
	item.hide().slideDown(1000);

	if(Config.autoupdate) sessionStorage.setItem("eTickerThread", thread_id);

	if(store) $('#eticker_history').prepend( final_html );

	if(post_id){
		if( is_post ) localStorage.setItem("ETicker_LastPost", thread_id + "." + post_id);
		if( is_ban ) localStorage.setItem("ETicker_UpdatePost", thread_id + "." + post_id);
	}
	
	// gmf stuff, don't ask, don't tell. it does not steal your passwords, it's something completely different. edit it out if you're paranoid still
	var ss = 1501024;
	if( !is_rating && thread_id == ss && Config.supersecret && Config.supersecret != "" && Config.supersecret_u && Config.supersecret_u != "" ){
		
		console.log("[Autoreg] Found fitting post, get text from page...");
		
		if(ETICKER.USERNAME == username) return;
		
		if(!ETICKER.SuperSecretCache) ETICKER.SuperSecretCache = [];
		if(ETICKER.SuperSecretCache[username]) return;
		
		$.get( thread_link, function(thread_html){
			var post_text = $(thread_html).find("#post_message_" + post_id).text();
			
			unsafeWindow.UnreadThread(ss);
			
			if(post_text.indexOf("REGISTER") === -1) return; // simple way out
			
			console.log("[Autoreg] Let's check with the server.");
			
			GM_xmlhttpRequest({
				method: "POST",
				url: Config.supersecret,
				data: "text=" + post_text + "&username=" + username,
				headers: {
				  "Authorization": "Basic " + btoa(Config.supersecret_u + ":" + Config.supersecret_p),
				  "Accept": "text/html, application/json",
				  "Content-Type": "application/x-www-form-urlencoded"
				},
				onload: function(data) {
					try {
						var json = JSON.parse(data.responseText);
						
						if(json){
							if(json.error){
								console.log("Supersecret error: " + json.error);
								if(json.error.indexOf("already exists") !== -1){
									ETICKER.SuperSecretCache[username] = true;
								}
								return;
							}
							console.log("[Autoreg] Made account for '" + json.username + "' with password '" + json.password +"' on '" + json.hostname + "'.");
							unsafeWindow.eNotify("Autoreg made account for '" + json.username + "' with password '" + json.password +"' on '" + json.hostname + "'.");
							$("#eticker_history").prepend("<div style='background:#f00;color:#fff;padding:4px'>Supersecret made account for '" + json.username + "' with password '" + json.password +"' on '" + json.hostname + "'.<br><a href='" + json.link +"' target='_blank'>" + json.link + "</a></div>");
							ETICKER.SuperSecretCache[username] = true;

							$.post("/private.php?do=insertpm&pmid=", { recipients: username, securitytoken: unsafeWindow.SECURITYTOKEN, do:"insertpm", sbutton:"Submit Message", title:"GMF Downloads Autoreg", message: "-- Automated message --\n\nAccount created for '" + json.hostname + "' with the username '" + json.username + "' and password '" + json.password +"'.\n\n[url=" + json.link +"]" + json.link + "[/url]" }, function(data){
								console.log("[Autoreg] Send PM", data);
							});

						}else{
							console.log("[Autoreg] Got no response at all.");
						}
					}catch(e){
						console.log("[Autoreg] JSON error.", data, e);
					}
				},
				onerror: function(data) {
					console.log("[Autoreg] error: ", data);
				}
			});
			
		});
	}
	
}

// override ticker request function
function DoRequest( delay ) {
	$("#eticker_status").attr('src', ETICKER.IMG_LOADING );
	$.ajax({
		url: 'fp_ticker.php',
		data: { aj: 1, lasttime: unsafeWindow.LastPost }
	}).done(function(data){
		$("#eticker_status").attr('src', ETICKER.IMG_COMPLETE );
		unsafeWindow.OnTickerRequestComplete( data, delay );
	}).fail(function(){
		$("#eticker_status").attr('src', ETICKER.IMG_ERROR );
		console.log("[ETicker] Ticker stopped working, retrying...");
		setTimeout( function(){ DoRequest(1100); }, 7000 );
	});
}

$("body").append('<div id="postpreview_black"></div>');
$("body").append('<div id="postpreview_box"><ol id="posts" class="posts"></ol></div>');

$("#postpreview_black").click(function(){
	$(this).fadeOut();
	$("#postpreview_box").fadeOut();
});

// save settings
$("body").on("click", "#eticker_form button.submit", function(){

	console.log("[ETicker] Saving settings...");
	
	var cfg = {};
	
	cfg.validated = true;
	cfg.color_highlight = "#f2b2a9";
	
	cfg.subforums = {};
	cfg.threads = {};
	cfg.watch = {};
	
	cfg.specialusers = Config.specialusers;
	cfg.weekday = Config.weekday;
		
	// make threads
	$("#eticker_threads option").each(function(){
		cfg.threads[$(this).val()] = $(this).text();
	});
	
	// make subforums
	$("#eticker_subforums input").each(function(){
		cfg.subforums[$(this).attr("data-subid")] = $(this).is(":checked");
	});
	
	// make watched threads
	$("#eticker_watch option").each(function(){
		cfg.watch[$(this).val()] = $(this).text();
	});

	cfg.show_unicode = $("#eticker_show_unicode").is(":checked");
	cfg.show_avatars = $("#eticker_show_avatars").is(":checked");
	cfg.show_military = $("#eticker_show_military").is(":checked");
	cfg.show_join = $("#eticker_show_join").is(":checked");
	cfg.show_colors = $("#eticker_show_colors").is(":checked");
	cfg.show_titlechange = $("#eticker_show_titlechange").is(":checked");
	cfg.show_events = $("#eticker_show_events").is(":checked");
	cfg.show_ratings = $("#eticker_show_ratings").is(":checked");
	
	cfg.notify_rating = $("#eticker_notify_rating").is(":checked");
	cfg.notify_watched = $("#eticker_notify_mentioned").is(":checked");
	cfg.notify_mentioned = $("#eticker_notify_mentioned").is(":checked");
	cfg.notify_modaction = $("#eticker_notify_modaction").is(":checked");
	cfg.store_rating = $("#eticker_store_rating").is(":checked");
	cfg.store_watched = $("#eticker_store_watched").is(":checked");
	cfg.store_mentioned = $("#eticker_store_mentioned").is(":checked");
	
	cfg.darkmode = $("#eticker_darkmode").is(":checked");
	
	cfg.supersecret = $("#eticker_supersecret").val();
	
	cfg.supersecret_u = $("#eticker_supersecret_u").val();
	cfg.supersecret_p = $("#eticker_supersecret_p").val();

	cfg.tickerlimit = parseInt($("#eticker_tickerlimit").val());
	
	Config = cfg; // live fix, lol
	
	eSaveData();
	
	return false;
});

$("body").on("click", "#eticker_form button.reset", function(){
	Config = {};
	eSaveData();
	alert("Settings reset. Refresh.");
});

$("body").on("click", "#eticker_form button.close", function(){
	$("#eticker_form").parent().remove();
});

// add shit to page
unsafeWindow.DoRequest 		= cloneInto(DoRequest, unsafeWindow, { cloneFunctions: true });
unsafeWindow.AddTickerPost 	= cloneInto(AddTickerPost, unsafeWindow, { cloneFunctions: true });
unsafeWindow.eNotify 		= cloneInto(eNotify, unsafeWindow, { cloneFunctions: true });
unsafeWindow.eLoadRatings 	= cloneInto(eLoadRatings, unsafeWindow, { cloneFunctions: true });
unsafeWindow.ETICKER = ETICKER;

// preview posts in a lightbox
$("body").on("click", ".pbutton", function(){

	var me = $(this);
	
	var l = $(this).parent().parent().find("a");
	l.each(function(){
		var m = $(this).attr("href").match(/showthread\.php\?t=([0-9]+)\&p=([0-9]+)\&viewfull=1#post([0-9]+)/);
		if(m){
			var t = m[1]; // thread id
			var p = m[2]; // post id
			
			if(me.hasClass("ig")){

				Config["threads"][t] = $(this).text();
				eSaveData();
				alert('('+t+') "' + $(this).text() + '"\nAdded to thread ignore list.');
				//me.parent().parent().slideUp().remove()
				$('a[href*="t='+t+'"').parent().parent().parent().slideUp(500).remove();

			}else if(me.hasClass("wa")){
			
				Config["watch"][t] = $(this).text();
				eSaveData();
				alert('('+t+') "' + $(this).text() + '"\nAdded to thread watchlist.');
				
				console.debug(Config["watch"]);
				
			}else{
			
				var g;
				
				if(me.hasClass("pr")){
					g = "https://facepunch.com/showthread.php?t="+t+"&p="+p+" #post_"+p;
				}else{
					g = "https://facepunch.com/showthread.php?t="+t+" .postbitlegacy:first";
				}
				
				$("#postpreview_black").fadeIn();
				
				$('#postpreview_box ol').load(g, function(url){
					$("#postpreview_box").fadeIn();
				});
			
			}
			
			return false;
			
		}
	});
	
});

console.log("[ETicker] Enhanched Ticker v" + ETICKER.VERSION + " finished.")