Guest User

Youtube Link Title

a guest
May 28th, 2015
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 36.56 KB | None | 0 0
  1. // ==UserScript==
  2. // @name YouTube Link Title
  3. // @description Adds video titles, shows previews and embeds on click. Also supported: Vimeo, LiveLeak, Dailymotion, vidme, WorldStarHipHop, Vine, Coub
  4. // @namespace http://w9p.co/userscripts/
  5. // @version 2015.5.5
  6. // @author kuehlschrank
  7. // @homepage http://w9p.co/userscripts/ytlt
  8. // @icon https://w9p.co/userscripts/ytlt/icon.png
  9. // @include http*
  10. // @exclude http*//*.google.*/*
  11. // @exclude *//*.googleapis.com/*
  12. // @exclude *//*.youtube.com/*
  13. // @exclude *//vimeo.com/*
  14. // @exclude *//*.vimeo.com/*
  15. // @exclude *//*.worldstarhiphop.com/*
  16. // @exclude *//vine.co/*
  17. // @exclude *//*.dailymotion.com/*
  18. // @exclude *//coub.com/*
  19. // @exclude *//vid.me/*
  20. // @exclude *//*.vid.me/*
  21. // @exclude *//*.reddit.com/toolbar/*
  22. // @exclude *://disqus.com/embed/*worldstarhiphop*
  23. // @grant GM_getValue
  24. // @grant GM_setValue
  25. // @grant GM_xmlhttpRequest
  26. // @grant GM_addStyle
  27. // @grant GM_registerMenuCommand
  28. // ==/UserScript==
  29.  
  30. 'use strict';
  31.  
  32. function onLoad() {
  33. if(location.hostname.indexOf('liveleak.com') > -1) {
  34. return location.pathname == '/ll_embed' && location.hash == '#play' ? location.href = 'javascript:void(jwplayer.api.selectPlayer().play());' : false;
  35. }
  36. cfg.load();
  37. var q = 'a[href*="//t.co/"]';
  38. for(var sid in sites) {
  39. q += sites[sid].patterns.reduce(function(prev, cur) { return prev + ',a[href*="' + cur +'"]'; }, '');
  40. }
  41. links.query = q;
  42. links.process(d.body);
  43. var M = window.MutationObserver;
  44. if(M) {
  45. var opts = location.hostname == 'www.facebook.com' ? {childList:true, subtree:true, attributes:true, attributeFilter:['href']} : {childList:true, subtree:true};
  46. new M(onMutations).observe(d.body, opts);
  47. } else {
  48. d.body.addEventListener('DOMNodeInserted', onNodeInserted);
  49. }
  50. window.addEventListener('message', onMessage);
  51. GM_registerMenuCommand('Set up YouTube Link Title', setup.show);
  52. }
  53.  
  54. function onNodeInserted(e) {
  55. var t = e.target;
  56. if(t.nodeType == 1) window.setTimeout(links.process, 100, t);
  57. }
  58.  
  59. function onMutations(muts) {
  60. for(var i = muts.length, m; i-- && (m = muts[i]);) {
  61. if(m.type == 'attributes') {
  62. window.setTimeout(links.process, 100, m.target);
  63. } else {
  64. for(var j = m.addedNodes.length, node; j-- && (node = m.addedNodes[j]);) {
  65. if(node.nodeType == 1) window.setTimeout(links.process, 100, node);
  66. }
  67. }
  68. }
  69. }
  70.  
  71. function onMessage(e) {
  72. if(typeof e.data != 'object' || !e.data.YTLT) return;
  73. var li = e.data.YTLT;
  74. if(window.frames.length > 1) {
  75. li.self = true;
  76. e.source.postMessage({YTLT:li}, '*');
  77. } else {
  78. popup.show(li);
  79. }
  80. }
  81.  
  82. function ce(n, props) {
  83. var n = d.createElement(n);
  84. if(props) {
  85. forEach(props, function(p) {
  86. if(p == 'click' || p == 'mousedown' || p == 'mousedown') {
  87. n.addEventListener(p, props[p]);
  88. } else {
  89. n[p] = props[p];
  90. }
  91. });
  92. }
  93. return n;
  94. }
  95.  
  96. function forEach(o, f) {
  97. var props = Object.keys(o);
  98. for(var i = props.length, p; i-- && (p = props[i]);) {
  99. if(o.hasOwnProperty(p)) f(p);
  100. }
  101. }
  102.  
  103. function rm(id) {
  104. var node = $(id);
  105. if(node) node.parentNode.removeChild(node);
  106. }
  107.  
  108. var d = document, $ = function(id) { return d.getElementById(id); }, log = function(s) { console.log(s); };
  109.  
  110. var setup = {
  111. id: 'YTLT-setup',
  112. html: function() {
  113. var h = '<div>YouTube Link Title</div><ul>';
  114. this.forEach(function(n) {
  115. var s = cfg.settings[n];
  116. if(typeof s.default == 'boolean') {
  117. h += '<li><input type="checkbox" name="'+ n +'"> ' + s.title + '</li>'
  118. } else if(s.options) {
  119. h += '<li>' + s.title + ': <select name="' + n + '">';
  120. forEach(s.options, function(on) {
  121. h += '<option value="' + on + '">' + s.options[on] +'</option>';
  122. });
  123. h += '</select></li>';
  124. } else if(typeof s.default == 'string') {
  125. h += '<li>' + s.title + ': <input type="text" name="'+ n +'" maxlength="' + s.maxlength + '" style="width:' + s.maxlength*12 +'px"></li>';
  126. }
  127. });
  128. return h += '</ul><div><button name="save">Save settings</button></div></div>';
  129. },
  130. q: function(n) {
  131. return d.querySelector('#' + this.id + ' *[name="' + n + '"]');
  132. },
  133. get: function(n) {
  134. var s = cfg.settings[n];
  135. if(typeof s.default == 'boolean') return this.q(n).checked;
  136. if(s.options) { var sel = this.q(n); return sel.options[sel.selectedIndex].value; }
  137. if(typeof s.default == 'string') return this.q(n).value;
  138. },
  139. set: function(n, val) {
  140. var s = cfg.settings[n];
  141. if(typeof s.default == 'boolean') {
  142. this.q(n).checked = val;
  143. } else if(s.options) {
  144. var sel = this.q(n);
  145. for(var i = sel.options.length; i--;) { if(sel.options[i].value == val) sel.selectedIndex = i; }
  146. } else if(typeof s.default == 'string') {
  147. this.q(n).value = val.trim();
  148. }
  149. },
  150. forEach: function(f) {
  151. forEach(cfg.settings, function(n) { if(cfg.settings[n].title) f(n); });
  152. },
  153. show: function() {
  154. rm(setup.id);
  155. GM_addStyle('\
  156. #'+setup.id+' { position:fixed;z-index:2147483647;top:40px;right:40px;padding:20px 30px;background-color:white;width:auto;border:1px solid black }\
  157. #'+setup.id+' * { color:black;text-align:left;line-height:normal;font-size:12px }\
  158. #'+setup.id+' div { text-align:center;font-weight:bold;font-size:14px }\
  159. #'+setup.id+' ul { margin:15px 0 15px 0;padding:0;list-style:none }\
  160. #'+setup.id+' li { margin:0;padding:3px 0 3px 0;vertical-align:middle }'
  161. );
  162. d.body.appendChild(ce('div', {id:setup.id,innerHTML:setup.html()}));
  163. setup.q('save').addEventListener('click', function() {
  164. if(setup.get('country') != cfg.country) cache.clear('yt');
  165. setup.forEach(function(n) { cfg[n] = setup.get(n); });
  166. cfg.x = cfg.y = false;
  167. cfg.save();
  168. this.disabled = true;
  169. this.innerHTML = 'Reloading...';
  170. location.reload();
  171. });
  172. setup.forEach(function(n) {
  173. setup.set(n, cfg[n]);
  174. setup.q(n).addEventListener('change', setup.update);
  175. });
  176. setup.update();
  177. },
  178. update: function() {
  179. setup.forEach(function(n) {
  180. var s = cfg.settings[n];
  181. if(!s.depends) return;
  182. setup.q(n).parentNode.style.display = (Object.keys(s.depends).every(function(dn) { return s.depends[dn].test(setup.get(dn)); })) ? '' : 'none';
  183. });
  184. }
  185. }
  186.  
  187. var links = {
  188. process: function(node) {
  189. var i = 0, list = node.tagName.toUpperCase() == 'A' ? [node] : node.querySelectorAll(links.query), isFB = location.hostname == 'www.facebook.com';
  190. if(list.length < 1) return;
  191. function processChunk() {
  192. var a, li, vi, num = 0, ae = d.activeElement;
  193. while(a = list[i++]) {
  194. if(!(li = links.parseInfo(a)) || ae && ae != d.body && ae.contains(a) || isFB && a.parentNode.outerHTML.indexOf('shareLink') > -1) continue;
  195. if((vi = cache.get(li.sid, li.vid)) || cfg.urls_only && !li.url) {
  196. links.decorate(a, li, vi);
  197. } else {
  198. (function(a, li) {
  199. net.info(li, function(vi) { links.decorate(a, li, vi); });
  200. })(a, li);
  201. }
  202. if(++num == 15) return window.setTimeout(processChunk, 100);
  203. }
  204. list = null;
  205. }
  206. node = null;
  207. processChunk();
  208. },
  209. parseInfo: function(a) {
  210. var url = a.getAttribute('data-expanded-url') || a.getAttribute('data-full-url') || a.href;
  211. try { url = decodeURIComponent(url.replace(/^https?:\/\/(?:www\.facebook\.com\/.+|sys\.4chan\.org\/derefer\?url=)(http.+)/, '$1')); } catch(ex) {};
  212. var test = function(pattern) { return this.indexOf(pattern.toLowerCase()) != -1; };
  213. for(var sid in sites) {
  214. var s = sites[sid], info;
  215. if(!sites[sid].patterns.some(test, url.toLowerCase())) continue;
  216. if(info = sites[sid].parse(url)) return {sid:sid,vid:info.vid,t:info.t,url:sites[sid].patterns.some(test, a.textContent.toLowerCase()),oUrl:url};
  217. }
  218. return null;
  219. },
  220. decorate: function(a, li, vi) {
  221. if(a.className.indexOf('YTLT-') > -1) {
  222. a.removeEventListener('click', this.onClick, false);
  223. a.removeEventListener('mouseover', this.onMouseOver, false);
  224. } else {
  225. if(!this.styleAdded) {
  226. var css = '\
  227. #YTLT-preview { position:fixed;z-index:2147483645;width:320px;padding:0;border:1px solid black;background-color:black; }\
  228. #YTLT-preview img { max-height:240px;width:inherit;vertical-align:bottom; }\
  229. #YTLT-preview div { padding:4px 2px;width:316px;text-align:center;font-family:sans-serif;font-size:13px;color:white;font-weight:bold; }\
  230. a.YTLT-na { text-decoration: line-through!important; }\
  231. a.YTLT-text { font-weight:bold!important;font-style:italic!important; }\
  232. a.YTLT-icon { padding-left:18px!important; }\
  233. a.YTLT-icon.YTLT-na:hover, a.YTLT-icon.YTLT-ne:hover { background:transparent url(data:image/gif;base64,R0lGODlhEAAQAKIGAO/v7+vr676+vmVlZZqamv///////wAAACH5BAEAAAYALAAAAAAQABAAAAM/aLrc/tAIQisRj4DCOSAZN4xDATpEV4zmMlVdWZ6GxqWr2Cq4mau0nk0VCHZelsuiBwypbpkNkcZAWjCRrCIBADs=) center left no-repeat!important; }';
  234. for(var sid in sites) {
  235. css += 'a.YTLT-icon-' + sid + ' { background:transparent url(' + sites[sid].icon + ') center left no-repeat!important; }';
  236. }
  237. GM_addStyle(css);
  238. this.styleAdded = true;
  239. }
  240. var c = ' YTLT-link';
  241. if(li.url || location.hostname == 'twitter.com') {
  242. c += ' YTLT-text YTLT-icon YTLT-icon-' + li.sid;
  243. if(vi) a.innerHTML = vi.title;
  244. } else {
  245. if(vi && !cfg.previews && vi.title) a.title = vi.title;
  246. if(a.hasChildNodes() && a.innerHTML.indexOf('<img') == -1 && a.textContent.trim()) {
  247. c += ' YTLT-icon YTLT-icon-' + li.sid;
  248. }
  249. }
  250. if(vi.status == 3 || vi.status == 4) {
  251. c += ' YTLT-na';
  252. } else if(vi.status == 5) {
  253. c += ' YTLT-ne';
  254. }
  255. a.className += c;
  256. if(cfg.rewrite && sites[li.sid].url) {
  257. a.href = sites[li.sid].url(li.vid, li.t, li.oUrl);
  258. }
  259. }
  260. if(cfg.embed_mode != 'off') {
  261. a.target = '_blank';
  262. if(!vi.status) {
  263. a.onclick = null;
  264. a.addEventListener('click', this.onClick);
  265. }
  266. }
  267. if(cfg.previews && (vi && vi.preview || sites[li.sid].preview) && !a.querySelector('iframe')) {
  268. a.addEventListener('mouseover', this.onMouseOver);
  269. new Image().src = embedding.preview(vi, li);
  270. }
  271. },
  272. onClick: function(e) {
  273. if(e.ctrlKey || e.altKey || e.shiftKey || e.metaKey || e.button != 0) return;
  274. e.preventDefault();
  275. e.stopImmediatePropagation();
  276. rm('YTLT-preview');
  277. embedding.play(this);
  278. },
  279. onMouseOver: function(e) {
  280. rm('YTLT-preview');
  281. var li = links.parseInfo(this);
  282. var vi = cache.get(li.sid, li.vid);
  283. var qm = d.compatMode == 'BackCompat';
  284. var w = qm ? d.body.clientWidth : d.documentElement.clientWidth, h = qm ? d.body.clientHeight : d.documentElement.clientHeight;
  285. var img = ce('img', {src:embedding.preview(vi, li)});
  286. var div = ce('div', {id:'YTLT-preview'});
  287. div.appendChild(img);
  288. if(vi.title && this.textContent.toLowerCase().indexOf(vi.title.toLowerCase()) == -1) div.appendChild(ce('div', {innerHTML:vi.title}));
  289. d.body.appendChild(div);
  290. var r = (this.firstElementChild || this).getBoundingClientRect();
  291. var dw = Math.max(div.offsetWidth, 320), dh = Math.max(div.offsetHeight, 240);
  292. if(h - r.height > 2*dh) {
  293. if(r.top + r.bottom > h) {
  294. div.style.bottom = h - r.top + 15 + 'px';
  295. } else {
  296. div.style.top = r.bottom + 15 + 'px';
  297. }
  298. div.style.left = Math.min(w - dw - 10, Math.max(10, e.pageX - dw/2)) + 'px';
  299. } else {
  300. if(r.right + r.left > w) {
  301. div.style.right = w - r.right + r.width + 15 + 'px';
  302. } else {
  303. div.style.left = r.left + r.width + 15 + 'px';
  304. }
  305. if(r.top+r.bottom > h) {
  306. div.style.bottom = Math.max(20, h - r.top - r.height/2 - dh/2) + 'px';
  307. } else {
  308. div.style.top = Math.max(10, r.top + r.height/2 - dh/2) + 'px';
  309. }
  310. }
  311. d.addEventListener('mouseout', links.onMouseOut);
  312. },
  313. onMouseOut: function(e) {
  314. d.removeEventListener('mouseout', links.onMouseOut, false);
  315. rm('YTLT-preview');
  316. }
  317. };
  318.  
  319. var net = {
  320. info: function(li, f) {
  321. var id = li.sid + li.vid;
  322. if(typeof net.pending[id] != 'object') {
  323. net.pending[id] = [f];
  324. sites[li.sid].request(li.vid, function(vi) {
  325. if(vi) {
  326. cache.set(li.sid, li.vid, vi);
  327. for(var i = net.pending[id].length; i--;) {
  328. window.setTimeout(net.pending[id][i], 0, vi);
  329. }
  330. }
  331. delete net.pending[id];
  332. });
  333. } else {
  334. net.pending[id].push(f);
  335. }
  336. },
  337. pending: {},
  338. json: function(url, f) {
  339. GM_xmlhttpRequest({
  340. method: 'GET',
  341. url: url,
  342. onload: function(req) {
  343. var obj;
  344. try {
  345. obj = JSON.parse(req.responseText);
  346. } catch(ex) {
  347. log('JSON data from ' + url + ' could not be parsed: ' + ex + '\nHTTP: ' + req.status + '\nResponse: ' + req.responseText);
  348. }
  349. window.setTimeout(f, 0, req.status, obj, req.responseText);
  350. },
  351. onerror: function(req) {
  352. log('Request to ' + url + ' failed.');
  353. window.setTimeout(f, 0, req.status, null, req.responseText);
  354. }
  355. });
  356. },
  357. text: function(url, re, f) {
  358. GM_xmlhttpRequest({
  359. method: 'GET',
  360. url: url,
  361. onload: function(req) {
  362. var m = [], txt = req.responseText;
  363. for(var i = 0, len = re.length; i < len; i++) {
  364. m.push(re[i].exec(txt));
  365. }
  366. window.setTimeout(f, 0, req.status, m);
  367. },
  368. onerror: function(req) {
  369. log('Request to ' + url + ' failed.');
  370. window.setTimeout(f, 0, req.status, []);
  371. }
  372. });
  373. }
  374. };
  375.  
  376. var embedding = {
  377. play: function(a) {
  378. var li = links.parseInfo(a);
  379. if(cfg.embed_mode == 'inline') {
  380. var embed = embedding.embed(li, cfg.big);
  381. a.parentNode.replaceChild(embed, a);
  382. window.setTimeout(window.scrollTo, 0, 0, window.scrollY + embed.getBoundingClientRect().top - window.innerHeight/2 + embed.offsetHeight/2);
  383. } else if(cfg.embed_mode == 'window' || location.hostname == 'api.solidopinion.com' && location.search.indexOf('nextbigfuture.com')) {
  384. var embed = embedding.embed(li, cfg.big);
  385. var w = parseInt(embed.style.width), h = parseInt(embed.style.height);
  386. embed.style.width = '100%';
  387. embed.style.height = '100%';
  388. var div = ce('div');
  389. div.appendChild(embed);
  390. var features = 'left='+(window.screen.width/2-w/2)+',top='+(window.screen.height/2-h/2)+',width='+w+',height='+h+',status=no,scrollbars=no,location=no,menubar=no,toolbar=no,personalbar=no,dependent=no';
  391. window.open('data:text/html,<html><title>Video Player</title><body style="padding:0;margin:0;overflow:hidden;background:black">' + encodeURIComponent(div.innerHTML) + '</body></html>', 'YouTube Link Title', features);
  392. div.removeChild(embed);
  393. } else if(cfg.embed_mode == 'player') {
  394. popup.show(li);
  395. }
  396. },
  397. embed: function(li, big) {
  398. var site = sites[li.sid], embed = ce('iframe', {className:'YTLT-embed'});
  399. embed.setAttribute('webkitAllowFullScreen', '');
  400. embed.setAttribute('allowfullscreen', '');
  401. embed.setAttribute('YTLT-sid', li.sid);
  402. embedding.resize(embed, big);
  403. embed.src = site.embed(li.vid, li.t);
  404. embed.style.display = 'block';
  405. return embed;
  406. },
  407. resize: function(embed, big) {
  408. var site = sites[embed.getAttribute('YTLT-sid')];
  409. var w = site.sizes[big?1:0][0];
  410. var h = site.sizes[big?1:0][1];
  411. embed.style.width = w + 'px';
  412. embed.style.height = h + 'px';
  413. },
  414. preview: function(vi, li) {
  415. if(vi && vi.preview) {
  416. return vi.preview;
  417. } else if(sites[li.sid].preview) {
  418. return sites[li.sid].preview(li.vid);
  419. }
  420. }
  421. };
  422.  
  423. var popup = {
  424. show: function(li) {
  425. if(window.top != window.self && !li.self) return window.parent.postMessage({YTLT:li}, '*');
  426. this.close();
  427. if(!this.styleAdded) {
  428. GM_addStyle('\
  429. #YTLT-bg { position:fixed;z-index:2147483647;top:0;right:0;bottom:0;left:0;background-color:black;opacity:0.9; }\
  430. #YTLT-player { display:block;position:fixed;z-index:2147483647;line-height:normal;background-color:black;border:2px solid black;font-size:13px;line-height:16px;padding:0;margin:0;left:auto;top:auto;right:auto;bottom:auto; }\
  431. #YTLT-player-titlebar { display:block;line-height:17px;padding:0;background:#1b1b1b;border-bottom:2px solid black;text-align:'+(cfg.reverse_buttons?'left':'right')+'; }\
  432. #YTLT-player-left { display:block;position:absolute;left:-6px;top:6px;bottom:6px;width:8px;padding:0;margin:0;background:none;cursor:ew-resize;s }\
  433. #YTLT-player-bottom { display:block;position:absolute;left:6px;right:6px;bottom:-6px;height:8px;padding:0;margin:0;background:none;cursor:ns-resize;s }\
  434. #YTLT-player-darken { padding:0px 11px 3px 11px; }\
  435. #YTLT-player-resize { padding:1px 11px 2px 11px; }\
  436. #YTLT-player-close { padding:0px 28px 3px 28px; }\
  437. #YTLT-player .YTLT-embed { border:0;line-height:normal; }\
  438. #YTLT-player .YTLT-player-titlebar-button { vertical-align:top;display:inline-block;margin:0;font-weight:bold;font-size:14px;text-decoration:none;border:0;border-'+(cfg.reverse_buttons?'right':'left')+':2px solid black;color:#757575;text-decoration:none;cursor:pointer;font-family:"segoe ui",verdana,sans-serif; }\
  439. #YTLT-player .YTLT-player-titlebar-button:hover { color:#959595!important; }\
  440. .YTLT-embed { display:block;background-color:black;border:2px solid black;margin:0;padding:0; }\
  441. #YTLT-player:not(.YTLT-player-resizing) .YTLT-embed { transition-property:width,height;transition-duration:500ms;transition-timing-function:ease; }\
  442. #YTLT-player.YTLT-player-moving { opacity:0.8;cursor:move;border:2px solid white; }\
  443. #YTLT-player.YTLT-player-resizing { opacity:0.8; }\
  444. #YTLT-player.YTLT-player-moving .YTLT-embed, #YTLT-player.YTLT-player-resizing .YTLT-embed { visibility:hidden; }\
  445. .YTLT-noselect { -moz-user-select:none;-webkit-user-select:none;-o-user-select:none; }'
  446. );
  447. this.styleAdded = true;
  448. }
  449. this.li = li;
  450. var titlebar = ce('div', {id:'YTLT-player-titlebar',mousedown:this.onTitlebarMouseDown});
  451. var buttons = [
  452. ce('a', {id:'YTLT-player-darken',className:'YTLT-player-titlebar-button YTLT-noselect',innerHTML:'&#9788;',click:this.onDarkenClick}),
  453. ce('a', {id:'YTLT-player-resize',className:'YTLT-player-titlebar-button YTLT-noselect',click:this.onResizeClick}),
  454. ce('a', {id:'YTLT-player-close',className:'YTLT-player-titlebar-button YTLT-noselect',innerHTML:'X',click:this.onCloseClick})
  455. ];
  456. if(cfg.reverse_buttons) buttons.reverse();
  457. for(var i = 0; i < buttons.length; i++) {
  458. titlebar.appendChild(buttons[i]);
  459. }
  460. var player = ce('div', {id:'YTLT-player'});
  461. player.appendChild(titlebar);
  462. player.appendChild(ce('div', {id:'YTLT-player-left',mousedown:this.onBorderMouseDown}));
  463. player.appendChild(ce('div', {id:'YTLT-player-bottom',mousedown:this.onBorderMouseDown}));
  464. player.appendChild(embedding.embed(li, cfg.big));
  465. if(cfg.darken) d.body.appendChild(ce('div', {id:'YTLT-bg'}));
  466. d.body.appendChild(player);
  467. this.update();
  468. var w = player.offsetWidth, h = player.offsetHeight;
  469. var x = parseFloat(cfg.x), y = parseFloat(cfg.y);
  470. var qm = d.compatMode == 'BackCompat';
  471. var cw = qm ? d.body.clientWidth : d.documentElement.clientWidth;
  472. var ch = qm ? d.body.clientHeight : d.documentElement.clientHeight;
  473. var mx = cw - x - w/2;
  474. var isPosValid = mx > 0 && mx < cw && y > -5 && y < ch - h/2;
  475. player.style.right = (isPosValid ? x : 80) + 'px';
  476. player.style.top = (isPosValid ? y : ch/2 - h/2) + 'px';
  477. d.addEventListener('keydown', this.onKeyDown);
  478. },
  479. close: function() {
  480. rm('YTLT-player');
  481. rm('YTLT-bg');
  482. d.removeEventListener('keydown', popup.onKeyDown, true);
  483. },
  484. update: function(e) {
  485. $('YTLT-player-resize').innerHTML = cfg.big ? '&#65293;' : '&#65291;';
  486. },
  487. onCloseClick: function(e) {
  488. e.preventDefault();
  489. popup.close();
  490. },
  491. onResizeClick: function(e) {
  492. e.preventDefault();
  493. cfg.big = !cfg.big;
  494. cfg.save();
  495. var embed = d.body.querySelector('#YTLT-player .YTLT-embed');
  496. embedding.resize(embed, cfg.big);
  497. popup.update();
  498. },
  499. onDarkenClick: function(e) {
  500. if($('YTLT-bg')) {
  501. rm('YTLT-bg');
  502. cfg.darken = false;
  503. cfg.save();
  504. } else {
  505. var player = $('YTLT-player');
  506. player.parentNode.insertBefore(ce('div', {id:'YTLT-bg'}), player);
  507. cfg.darken = true;
  508. cfg.save();
  509. }
  510. },
  511. onKeyDown: function(e) {
  512. if(e.keyCode == 27) popup.close();
  513. },
  514. onTitlebarMouseDown: function(e) {
  515. var t = e.target;
  516. if(t.id != 'YTLT-player-titlebar') return;
  517. t.parentNode.className = 'YTLT-player-moving';
  518. var r = t.getBoundingClientRect();
  519. t.dx = e.clientX - r.left;
  520. t.dy = e.clientY - r.top;
  521. d.body.className += ' YTLT-noselect';
  522. d.addEventListener('mousemove', popup.onTitlebarMouseMove);
  523. d.addEventListener('mouseup', popup.onTitlebarMouseUp);
  524. },
  525. onTitlebarMouseMove: function(e) {
  526. var titlebar = $('YTLT-player-titlebar');
  527. titlebar.parentNode.style.right = (d.compatMode == 'BackCompat' ? d.body.clientWidth : d.documentElement.clientWidth) - e.clientX - titlebar.offsetWidth + titlebar.dx - 2 + 'px';
  528. titlebar.parentNode.style.top = e.clientY - titlebar.dy - 2 + 'px';
  529. },
  530. onTitlebarMouseUp: function(e) {
  531. var titlebar = $('YTLT-player-titlebar');
  532. titlebar.parentNode.className = '';
  533. titlebar.dx = null;
  534. titlebar.dy = null;
  535. d.removeEventListener('mousemove', popup.onTitlebarMouseMove, false);
  536. d.removeEventListener('mouseup', popup.onTitlebarMouseUp, false);
  537. d.body.className = d.body.className.replace('YTLT-noselect', '');
  538. cfg.x = parseInt(titlebar.parentNode.style.right);
  539. cfg.y = titlebar.parentNode.style.top;
  540. cfg.save();
  541. },
  542. onBorderMouseDown: function(e) {
  543. var embed = d.body.querySelector('#YTLT-player .YTLT-embed');
  544. embed.parentNode.className = 'YTLT-player-resizing';
  545. var r = embed.getBoundingClientRect();
  546. embed.ratio = r.width/r.height;
  547. embed.anchor = [r.right, r.top];
  548. embed.control = e.target.id;
  549. d.body.className += ' YTLT-noselect';
  550. d.addEventListener('mousemove', popup.onBorderMouseMove);
  551. d.addEventListener('mouseup', popup.onBorderMouseUp);
  552. },
  553. onBorderMouseMove: function(e) {
  554. var embed = d.body.querySelector('#YTLT-player .YTLT-embed'), w, h;
  555. if(embed.control == 'YTLT-player-left') {
  556. var dx = embed.anchor[0] - e.clientX;
  557. w = dx;
  558. h = dx / embed.ratio;
  559. } else {
  560. var dy = e.clientY - embed.anchor[1];
  561. w = embed.ratio * dy;
  562. h = dy;
  563. }
  564. embed.style.width = w + 'px';
  565. embed.style.height = h + 'px';
  566. },
  567. onBorderMouseUp: function(e) {
  568. var embed = d.body.querySelector('#YTLT-player .YTLT-embed');
  569. embed.parentNode.className = '';
  570. embed.x = null;
  571. embed.y = null;
  572. embed.w = null;
  573. embed.h = null;
  574. d.removeEventListener('mousemove', popup.onBorderMouseMove, false);
  575. d.removeEventListener('mouseup', popup.onBorderMouseUp, false);
  576. d.body.className = d.body.className.replace('YTLT-noselect', '');
  577. },
  578. };
  579.  
  580. var sites = {
  581. 'yt':{
  582. patterns:["youtube.com", "youtu.be", "youtube.googleapis.com"],
  583. parse:function(url) { return /^https?:\/\/((www\.|m\.)?youtu(\.be|be\.(googleapis\.)?com).+v[=\/]|#p\/[a-z]\/.+\/|youtu\.be\/)([a-z0-9_-]{8,})(.*[#&\?]t=([0-9hms]+))?/i.exec(url) ? {vid:RegExp.$5, t:RegExp.$7} : null; },
  584. sizes:[[640,390],[853,510]],
  585. embed:function(vid, t) { var m = /((\d+)h)?((\d+)m)?(\d+)?/.exec(t); t = parseInt(m[2] || 0)*3600 + parseInt(m[4] || 0)*60 + parseInt(m[5] || 0); return 'https://www.youtube.com/embed/' + vid + '?autoplay=1&rel=1' + (t ? '&start=' + t : ''); },
  586. url:function(vid, t, oUrl) { return 'https://www.youtube.com/watch?v=' + vid + (/\b(list=[a-z0-9_-]+)/i.exec(oUrl) ? '&' + RegExp.$1 : '') + (t ? '#t=' + t : ''); },
  587. preview:function(vid) { return 'https://img.youtube.com/vi/' + vid + '/0.jpg'; },
  588. icon:'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAABGdBTUEAALGPC/xhBQAAAMZQTFRFkQ0IyBILyBILkQ0IyBILkQ0IkQ0IyBILyBILkQ0IpA8JmQ4JlQ4Ing4JuxEKtRAKwBEKxBELyBILkQ0IAAAA+fn5wRcQtR0Yvh8YqRsWrx0XoxsV56Wj8vLy9+/vyTMttxgS252b6Ojo0WNfnRcTy8jIlg4JzL+/XAgFjjAtdAoHiFNRmA4IbxQQgQwI05qYmw4JrI2M8fHx1dXV5+fn3d3dkQ0IpA8JtRAKyBILng4Jqg8JrxAKuxEKmQ4JwBEKxBELlQ4ItxbjVAAAABV0Uk5TCaUJBvmihNKi2PzMh+rq/MyHzMwAD5S0KQAAAItJREFUGNOFz8cWgjAARNGxKx2CvWDvFRILCuj//5QJcYMuvKt3Zjdwv+BnyOec4u2j4lRd2M8MG1bCNXpeIlkwIq5VH0yilAHzyjV9vz8aijLxEDqU0vEhTdyFNmNssUoTyoXrBsFptxWlQA+56WyzPooIdagxN1/uY0mF9srQgBIhZ6lGSLmAv2/fr2gov1/MElQAAAAASUVORK5CYII=',
  589. request:function(vid, f) {
  590. var part = ['snippet', 'status'], fields = ['id', 'snippet/title', 'status/privacyStatus', 'status/embeddable'], country;
  591. if(cfg.country) {
  592. country = cfg.country.toUpperCase();
  593. part.push('contentDetails');
  594. fields.push('contentDetails/regionRestriction');
  595. }
  596. net.json('https://www.googleapis.com/youtube/v3/videos?id=' + vid + '&part=' + part.join(',') + '&fields=items(' + fields.join(',') + ')&' + window.atob('a2V5PUFJemFTeURXeE9yNExpNEE2SHRZeDlrN2JWYkNRNjh2cHdKSnVvYw=='), function(code, obj, txt) {
  597. var item = obj.items[0];
  598. if(code != 200) {
  599. window.setTimeout(f, 0);
  600. } else if(!item) {
  601. window.setTimeout(f, 0, {title:'Video not found', status:4});
  602. } else if(item.status.privacyStatus == 'private') {
  603. window.setTimeout(f, 0, {title:'Private video', status:3});
  604. } else {
  605. var status;
  606. if(item.contentDetails && item.contentDetails.regionRestriction) {
  607. var rr = item.contentDetails.regionRestriction;
  608. if(rr.blocked && rr.blocked.indexOf(country) > -1 || rr.allowed && rr.allowed.indexOf(country) < 0) status = 3;
  609. } else if(!item.status.embeddable) {
  610. status = 5;
  611. }
  612. window.setTimeout(f, 0, {title:item.snippet.title, status:status});
  613. }
  614. });
  615. }
  616. },
  617. 'vm':{
  618. patterns:["vimeo.com"],
  619. parse:function(url) { return /^https?:\/\/vimeo\.com\/(m\/)?([0-9]+)/i.exec(url) ? {vid:RegExp.$2} : null; },
  620. sizes:[[640,360],[853, 480]],
  621. embed:function(vid, t) { return 'https://player.vimeo.com/video/' + vid + '?title=1&portrait=1&byline=1&color=aa0000&autoplay=1'; },
  622. url:function(vid, t) { return 'https://vimeo.com/' + vid; },
  623. icon:'data:image/gif;base64,R0lGODlhEAAQAMQfAAuUuQynzzu83u/09Ryy2Su320rC4IbW6mKOngqHq5GvuoO3xhVbc0m92zV7keDo60R8j8Hc5KHEzwuawGSluaTg8Ah1lfD5/BmPsJPI13fR6LLd6f///wuavg2t1gAAACH5BAEAAB8ALAAAAAAQABAAAAVu4NeNZFmKgqeurCqMbbzCbrEWh0ao9MFdNgNnWOF1CJUhR+PZDIYRY2MRGWYIFsVQYgRYHNBAc4gwqiaPoUfIkQDMKsnwkB5YZp0VRTmEsGgeGHwIb3grAVoDCAktgB4WEAyMjY4AYpQiJpojHyEAOw==',
  624. request:function(vid, f) {
  625. net.json('https://vimeo.com/api/oembed.json?url=http://vimeo.com/' + vid, function(code, obj) {
  626. if(code == 404) {
  627. window.setTimeout(f, 0, {title:'Video not found', status:4});
  628. } else if(code == 403) {
  629. window.setTimeout(f, 0, {title:'Unknown video', status:5});
  630. } else if(code == 200 && obj) {
  631. window.setTimeout(f, 0, {title:obj.title ? obj.title : 'Unknown video', preview:obj.thumbnail_url});
  632. } else {
  633. window.setTimeout(f, 0);
  634. }
  635. });
  636. }
  637. },
  638. 'vn':{
  639. patterns:["vine.co"],
  640. parse:function(url) { return /^https?:\/\/(www\.)?vine\.co\/v\/([a-z0-9]+)/i.exec(url) ? {vid:RegExp.$2} : null; },
  641. sizes:[[500,500],[660,660]],
  642. embed:function(vid) { return 'https://vine.co/v/' + vid + '/card?mute=0'; },
  643. url:function(vid) { return 'https://vine.co/v/' + vid; },
  644. icon:'data:image/gif;base64,R0lGODlhEAAQALMAAAqnfLXk1/b7+jS1ks3t5JvZyFbBpOf28onSvhirhHLLswCjdgCkdwCjd////wCkeCH5BAAAAAAALAAAAAAQABAAAARp8Mk5TQgoNbqrcGCgMQZiUISDHcK5IE4xDezQBI6yvOpcPzjdwtCbBAEpF+1gkygchIEis0kkdwwr1DUpFCUDnOAgHI6bTtABQcGJGA1tYeTJSWBMLAU//ZQ5AF4fMQCAe36FhhQGXBQRADs=',
  645. request:function(vid, f) {
  646. net.text('https://vine.co/v/' + vid, [/"og:title" content="(.+?)">/, /"og:image" content="(.+?)"/], function(code, m) {
  647. var title = m[0], preview = m[1];
  648. if(code == 404) {
  649. window.setTimeout(f, 0, {title:'Video not found', status:4});
  650. } else if(code == 200 && title) {
  651. window.setTimeout(f, 0, {title:title ? title[1] : 'Unknown video', preview:preview ? preview[1] : null});
  652. } else {
  653. window.setTimeout(f, 0);
  654. }
  655. });
  656. }
  657. },
  658. 'll':{
  659. patterns:["liveleak.com/view"],
  660. parse: function(url) { return /^https?:\/\/(m|www)\.liveleak\.com\/view.+i=([0-9a-z_]+)/i.exec(url) ? {vid:RegExp.$2} : null; },
  661. sizes:[[625,352],[852,480]],
  662. embed:function(vid) { return 'http://www.liveleak.com/ll_embed?i=' + vid + '#play'; },
  663. url:function(vid) { return 'http://www.liveleak.com/view?i=' + vid; },
  664. icon:'data:image/gif;base64,R0lGODlhEAAQAIAAAPz8/JcAACH5BAAAAAAALAAAAAAQABAAAAIrjI+pB+1gWoLhRcqurDhqumXcFnoj2FXfNa1ce7IISqb0DcJPPi+f4wsWAAA7',
  665. request:function(vid, f) {
  666. net.text('http://www.liveleak.com/view?i=' + vid, [/Item not found!/i, /<title>LiveLeak\.com - (.+?)<\/title>/i, /"og:image" content="(.+?)"/], function(code, m) {
  667. var notfound = m[0], title = m[1], preview = m[2];
  668. if(notfound) {
  669. window.setTimeout(f, 0, {title:'Video not found', status:4});
  670. } else if(code == 200 && title) {
  671. window.setTimeout(f, 0, {title:title ? title[1] : 'Unknown video', preview:preview ? preview[1].replace('_thumb_', '_sf_') : null});
  672. } else {
  673. window.setTimeout(f, 0);
  674. }
  675. });
  676. }
  677. },
  678. 'wh':{
  679. patterns:["worldstarhiphop.com"],
  680. parse: function(url) { return /^https?:\/\/(www\.|m\.)?worldstarhiphop\.com\/.+v=([a-z0-9]+)/i.exec(url) ? {vid:RegExp.$2} : null; },
  681. sizes:[[448,374],[640,534]],
  682. embed:function(vid) { return 'http://www.worldstarhiphop.com/videos/ea/16711680/' + vid; },
  683. url:function(vid) { return 'http://www.worldstarhiphop.com/videos/video.php?v=' + vid; },
  684. icon:'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAXpJREFUeNpsUt1KAkEY/Ry2yx6gF4gQIXoakZAQkegqQiJ6gIiIJSQkRGSRiPCqNzGjve8JvOoq+Tz2nZnZbakGnf1+ztlz5tuprV9mEpdzIrAHBI7PMnE+BYhIFEowK0kkqGw1m1b7ms2YIHGJYRIDusQIiigALRXC8u8C68QoFVRqoff5PKUHtqVxeJQ/TU2+0WrnVofz73DbrTZ9L6fZjtEVK9X4E1mFNATQkBps+Zg5VV1ko712R+OijxiWgaoBFtnYAp4dQD4Z1zs9ixrdHo+D8BcrWt/2fDKiXdj8YKehrvV3uydmYz4aWnEFzMdDkHNsu6WgPdgASKCxh3t68ONQVOyJsFUUah/DQRiPxI1JUWASZx6HyO+gJaF+2pcCVyXkg7RC8IfjDfB5fpcW4J8VMKHqCYjstYmcUWQj8Ytu/P6e3pSaCeDVHMf4ll47+hd/44J1t9+/QCz5C+cJEmZ/cH4p/y14F/DDSKqN19urvwq/yN8CDAB9dTAcPA3GZgAAAABJRU5ErkJggg==',
  685. request:function(vid, f) {
  686. net.text('http://www.worldstarhiphop.com/videos/video.php?v=' + vid, [/<title>(Video: )?(.+?)\s*(\(\*Warning|<\/title>)/i, /"image_src" href="(.+?)"/], function(code, m) {
  687. var title = m[0], preview = m[1];
  688. if(title) {
  689. window.setTimeout(f, 0, {title:title[2], preview:preview ? preview[1] : null});
  690. } else {
  691. window.setTimeout(f, 0);
  692. }
  693. });
  694. }
  695. },
  696. 'dm':{
  697. patterns:["dailymotion.com/video"],
  698. parse:function(url) { return /^https?:\/\/www\.dailymotion\.com\/video\/([a-z0-9]+)(.+start=([0-9]+))?/i.exec(url) ? {vid:RegExp.$1,t:RegExp.$3} : null; },
  699. sizes:[[620,352],[853,480]],
  700. embed:function(vid, t) { return 'https://www.dailymotion.com/embed/video/' + vid + '?logo=0&autoplay=1' + (t ? '&start=' + t : ''); },
  701. url:function(vid, t) { return 'https://www.dailymotion.com/video/' + vid + (t ? '?start=' + t : ''); },
  702. icon:'data:image/gif;base64,R0lGODlhEAAQAMQAAGB0hvHXCi5aq6mYZThltsiUCEd1ydmlAXSImMi1g7KCDePUZdO3TjJWl5dpBf7wAT5jpNrPkNCsJyVQnOzBBJ6klcCYLx1Jmdvh62WT5fLiKYV3V9W8Gr27tUlrqjVYlyH5BAAAAAAALAAAAAAQABAAAAWfIAZ5ZGmSkJgZbOuyGQQZRF1Xnl0bMm0jHISOwJv9FhSJ0Mb76CqLg2JAENg+TisBoTk4NoKw9dOoCjyVQOHrERMaDcFk4mEEvIoORAyXQwYcDwcFBxYJewJ9Fx0SAYIHFAoFHxOJDRMXCQWOB5CSCHNwmAMKD48UBQUJFxNwFxcWEqadqIavlwIXHwARCxYWDBEAEBdyGK1YycpkExghADs=',
  703. request:function(vid, f) {
  704. net.json('https://www.dailymotion.com/services/oembed?format=json&url=http://www.dailymotion.com/video/' + vid, function(code, obj) {
  705. if(code == 404) {
  706. window.setTimeout(f, 0, {title:'Video not found', status:4});
  707. } else if(code == 200 && obj) {
  708. window.setTimeout(f, 0, {title:obj.title ? obj.title : 'Unknown video', preview:obj.thumbnail_url});
  709. } else {
  710. window.setTimeout(f, 0);
  711. }
  712. });
  713. }
  714. },
  715. 'cb':{
  716. patterns:["coub.com/view/"],
  717. parse:function(url) { return /^https?:\/\/coub\.com\/view\/([a-z0-9]+)/i.exec(url) ? {vid:RegExp.$1} : null; },
  718. sizes:[[640,360],[853,480]],
  719. embed:function(vid, t) { return 'http://coub.com/embed/' + vid + '?muted=false&autostart=true&noSiteButtons=true'; },
  720. url:function(vid, t) { return 'http://coub.com/view/' + vid; },
  721. icon:'data:image/gif;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAAWlBMVEUAAAADM/8AIP8DMv8AK/8DMv8DMv8AMP8EMv8EMv8EM/8DMv////8UQP+Dmv9kgf/t8P/M1v/j6f8dSP96k//Z4f+Mov/Bzf8MOf+0wv87X/91j/+Yq/9rhv9szalUAAAACnRSTlMAvwjCBpSYKo/huP286QAAAHpJREFUGNNlj9sSgyAMRGkrBQ4R1Kq9//9vCiqOo+ctmWx2V2WMdd47a9RCpVm5X+f5wsatSgvNDp30QD02ItKMDzDKprmVto+hkwhWOQjyfuW7bw1OeXjKh4I/LthL+ixZnw4hhkH+YBfb0GXbX7Y9BjtFP5cr9Sn1JyOZCa2SfTdfAAAAAElFTkSuQmCC',
  722. request:function(vid, f) {
  723. net.json('http://coub.com/api/oembed.json?url=http://coub.com/view/' + vid, function(code, obj) {
  724. if(code == 404) {
  725. window.setTimeout(f, 0, {title:'Video not found', status:4});
  726. } else if(code == 403) {
  727. window.setTimeout(f, 0, {title:'Unknown video', status:5});
  728. } else if(code == 200 && obj) {
  729. window.setTimeout(f, 0, {title:obj.title ? obj.title : 'Unknown video', preview:obj.thumbnail_url});
  730. } else {
  731. window.setTimeout(f, 0);
  732. }
  733. });
  734. }
  735. },
  736. 'vd':{
  737. patterns:["vid.me/"],
  738. parse:function(url) { return /^https?:\/\/vid\.me\/([a-z0-9]+)$/i.exec(url) ? {vid:RegExp.$1} : null; },
  739. sizes:[[640,360],[853,480]],
  740. embed:function(vid, t) { return 'https://vid.me/e/' + vid + '?autoplay=1'; },
  741. url:function(vid, t) { return 'https://vid.me/' + vid; },
  742. icon:'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAAjVBMVEUAAAA+Pj4pKSkqKionJycrKystLS1KSkpJSUk0NDQ0NDQtLS3///8tLS0rKyspKSlvb281NTXKysrDw8O/v79OTk7b29ujo6ONjY2KiopnZ2dYWFjX19e4uLg8PDz29vbt7e3Ozs6xsbGnp6eWlpaHh4d3d3dmZmZaWlpISEgwMDC5ubl1dXVqampoaGjlr6SgAAAADHRSTlMA/KqVSxoH8O/m5bPyShVZAAAAt0lEQVQY02WPRxKDMAxFjXGAAHLD9N5Lyv2PF9vDLm+hGX1p8T7SeAQ/HeeJiYcsDzcoVdOoMnAfdo94FlsyHunEc/kQ3wzc9RAJ7P3+CQjCZdw387ptaz72cYlRqEbeUWYQh1IhcpKaifMCuE7B0sTRQSqW6U0pnxZhgrCtRN3VAHV3iKoNES5yqgEwIy8wIr7cGVhYJX1ixOQXGKUMdqnFrLqcP2la5dKo23J+8UqStvBNub/6P7zKDtYRJLbHAAAAAElFTkSuQmCC',
  743. request:function(vid, f) {
  744. net.text('https://vid.me/' + vid, [/"og:title" content="(.+?)">/, /"og:image" content="(.+?)"/], function(code, m) {
  745. var title = m[0], preview = m[1];
  746. if(code == 404) {
  747. window.setTimeout(f, 0, {title:'Video not found', status:4});
  748. } else {
  749. window.setTimeout(f, 0, {title:title ? title[1] : 'Unknown video', preview:preview ? preview[1] : null});
  750. }
  751. });
  752. }
  753. }
  754. };
  755.  
  756. var cache = {
  757. get: function(sid, vid) {
  758. if(!cache.obj) cache.load();
  759. var data = cache.obj[sid + vid];
  760. if(!data) return false;
  761. data = data.split('\t');
  762. if(sid == 'yt' && data[0] == 'https://youtube.com/devicesupport') return false;
  763. return data[0] ? {title:data[0],status:data[1],preview:data[2]} : false;
  764. },
  765. set: function(sid, vid, info) {
  766. if(!info) return;
  767. cache.load();
  768. cache.obj[sid + vid] = [info.title,info.status,info.preview].join('\t').trim();
  769. cache.save();
  770. },
  771. save: function() {
  772. if(!cache.obj) return;
  773. try {
  774. cache.clean();
  775. GM_setValue('cache', JSON.stringify(cache.obj));
  776. } catch(ex) { log('Error while saving cache: ' + ex); }
  777. cache.obj = null;
  778. },
  779. load: function() {
  780. try {
  781. cache.obj = JSON.parse(GM_getValue('cache'));
  782. } catch(ex) { }
  783. if(cache.obj == null || typeof(cache.obj) != 'object') cache.obj = {};
  784. },
  785. clean: function() {
  786. var overflow = Object.keys(cache.obj).length - 300;
  787. if(overflow < 1) return;
  788. var i = 0, f = Object.prototype.hasOwnProperty;
  789. for(var p in cache.obj) {
  790. if(f.call(cache.obj, p)) {
  791. delete cache.obj[p];
  792. if(++i == overflow + 20) return;
  793. }
  794. }
  795. },
  796. clear: function(sid) {
  797. cache.load();
  798. var f = Object.prototype.hasOwnProperty;
  799. for(var p in cache.obj) {
  800. if(p.indexOf(sid) == 0 && f.call(cache.obj, p)) {
  801. delete cache.obj[p];
  802. }
  803. }
  804. cache.save();
  805. }
  806. };
  807.  
  808. var cfg = {
  809. settings: {
  810. country: { title:'Check for restrictions? Enter your <a href="http://en.wikipedia.org/wiki/ISO_3166-1_alpha-2#Officially_assigned_code_elements" target="_blank" style="text-decoration:underline!important;" title="e.g. US, GB or DE">country code</a>', default:'', maxlength:2},
  811. reverse_buttons: { title:'Move buttons to the left', default:false, depends:{embed_mode:/player/} },
  812. big: { title:'480p instead of 360p', default:false, depends:{embed_mode:/window|inline/} },
  813. embed_mode: { title:'Embed on click', default:'player', options:{off:'off', player:'in-page popup', inline:'inline', window:'popup window'} },
  814. rewrite: { title:'Rewrite addresses to non-mobile HTTPS URLs', default:true },
  815. urls_only: { title:'Look up info only when link text is URL', default:false },
  816. previews: { title:'Show preview image on hover', default:true },
  817. darken: {},
  818. x: {},
  819. y: {}
  820. },
  821. load: function() {
  822. forEach(cfg.settings, function(n) { cfg[n] = GM_getValue(n, cfg.settings[n].default); });
  823. },
  824. save: function() {
  825. forEach(cfg.settings, function(n) { if(typeof cfg[n] != 'undefined') GM_setValue(n, cfg[n]); });
  826. }
  827. };
  828.  
  829. window.setTimeout(onLoad, 100);
Advertisement
Add Comment
Please, Sign In to add comment