Blur Title Reddit

Blurring a title which marked as spoiler in reddit, just like in fallout subreddit.

  1. // ==UserScript==
  2. // @name Blur Title Reddit
  3. // @namespace https://greasyfork.org/users/102866
  4. // @description Blurring a title which marked as spoiler in reddit, just like in fallout subreddit.
  5. // @include https://*.reddit.com/*
  6. // @include http://*.reddit.com/*
  7. // @exclude https://*.reddit.com/r/*/comments/*
  8. // @exclude http://*.reddit.com/r/*/comments/*
  9. // @author TiLied
  10. // @version 0.8.00
  11. // @grant GM_listValues
  12. // @grant GM_getValue
  13. // @grant GM_setValue
  14. // @grant GM_deleteValue
  15. // @require https://greasemonkey.github.io/gm4-polyfill/gm4-polyfill.js
  16. // @grant GM.listValues
  17. // @grant GM.getValue
  18. // @grant GM.setValue
  19. // @grant GM.deleteValue
  20. // ==/UserScript==
  21.  
  22. class BlurTitleReddit
  23. {
  24. constructor()
  25. {
  26. console.log("Blur Title Reddit v" + GM.info.script.version + " initialization");
  27.  
  28. this.Debug = false;
  29.  
  30. this.btr_pTitle = false;
  31. this.asterisk = true;
  32. this.Scroll = 1;
  33.  
  34. this._FirstTime();
  35. this._SetCSS();
  36. }
  37.  
  38. _SetCSS()
  39. {
  40. document.head.append("<!--Start of Blur Title Reddit v" + GM.info.script.version + " CSS-->");
  41.  
  42. document.head.insertAdjacentHTML("beforeend", `<style type="text/css">bdi.btr_title:hover \
  43. { \
  44. color:inherit!important; \
  45. background:transparent!important; \
  46. text-decoration:none!important; \
  47. text-shadow:0 0.1px 0 #dcddce \
  48. }</style>`);
  49.  
  50. document.head.insertAdjacentHTML("beforeend", `<style type="text/css">bdi.btr_title { \
  51. color:rgba(255,60,231,0) !important; \
  52. text-shadow: 0px 0px 1em black; \
  53. padding: 0 2px; \
  54. }</style>`);
  55.  
  56. document.head.insertAdjacentHTML("beforeend", `<style type="text/css">bdi.btr_trans \
  57. { \
  58. transition: all 0.5s ease; \
  59. }</style>`);
  60.  
  61. document.head.insertAdjacentHTML("beforeend", `<style type="text/css">.btr_closeButton\
  62. { \
  63. cursor: pointer; \
  64. text-align: center; \
  65. font-size: 11px; \
  66. float:right; \
  67. margin-top:0px; \
  68. border:1px solid #AAA; \
  69. width:16px; \
  70. height:16px; \
  71. }</style>`);
  72.  
  73. document.head.insertAdjacentHTML("beforeend", `<style type="text/css">.btr_closeButton:hover \
  74. { \
  75. border:1px solid #999; \
  76. background-color: #ddd; \
  77. }</style>`);
  78.  
  79. document.head.insertAdjacentHTML("beforeend", `<style type="text/css">.title \
  80. { \
  81. overflow: visible !important; \
  82. }</style>`);
  83.  
  84. document.head.insertAdjacentHTML("beforeend", `<style type="text/css">"div.btr_opt { \
  85. position: fixed; bottom: 0; right: 0; border: 0; z-index: 500;\
  86. }</style>`);
  87.  
  88. document.head.append("<!--End of Blur Title Reddit v" + GM.info.script.version + " CSS-->");
  89. }
  90.  
  91. async _FirstTime()
  92. {
  93. if (this.HasValueGM("btr_GMTitle", false))
  94. {
  95. this.btr_pTitle = await GM.getValue("btr_GMTitle");
  96. }
  97.  
  98. if (this.HasValueGM("btr_asterisk", true))
  99. {
  100. this.asterisk = await GM.getValue("btr_asterisk");
  101. }
  102.  
  103. //Console log prefs with value
  104. console.log("*prefs:");
  105. console.log("*-----*");
  106. let vals = await GM.listValues();
  107.  
  108. //Find out that var in for block is not local... Seriously js?
  109. for (let i = 0; i < vals.length; i++)
  110. {
  111. console.log("*" + vals[i] + ":" + await GM.getValue(vals[i]));
  112. }
  113. console.log("*-----*");
  114. }
  115.  
  116. Main()
  117. {
  118. window.onscroll = function (ev)
  119. {
  120. if (window.pageYOffset >= window.innerHeight * btr.Scroll)
  121. {
  122. btr.Core();
  123.  
  124. btr.Scroll += 1;
  125. }
  126. };
  127.  
  128. this.Core();
  129.  
  130. //Set UI of settings
  131. //TODO UI!
  132. //this.OptionsUI();
  133. }
  134.  
  135. Core()
  136. {
  137. let _titlesDivQ = document.querySelectorAll("div.spoiler");
  138. let _titlesDiv = [];
  139.  
  140. if (_titlesDivQ.length == 0)
  141. {
  142. function _IsSpoiler(_el)
  143. {
  144. let _spans = _el.querySelectorAll("span");
  145.  
  146. if (btr.Debug)
  147. console.log(_el.querySelectorAll("span"));
  148.  
  149. for (let i = 0; i <= _spans.length; i++)
  150. {
  151. if (i == _spans.length)
  152. return false;
  153.  
  154. if (_spans[i].textContent == 'spoiler')
  155. return true;
  156. }
  157. }
  158.  
  159. let _titles = document.querySelectorAll(".Post");
  160.  
  161. for (let i = 0; i < _titles.length; i++)
  162. {
  163. if (_IsSpoiler(_titles[i]))
  164. {
  165. _titlesDiv.push(_titles[i]);
  166. }
  167. }
  168. } else
  169. {
  170. for (let i = 0; i < _titlesDivQ.length; i++)
  171. {
  172. _titlesDiv.push(_titlesDivQ[i]);
  173. }
  174. }
  175.  
  176. if (_titlesDiv != this.titlesDiv)
  177. {
  178. if (this.Debug)
  179. console.log(_titlesDiv);
  180.  
  181. this.titlesDiv = _titlesDiv;
  182.  
  183. for (let i = 0; i < _titlesDiv.length; i++)
  184. {
  185. if (_titlesDiv[i].querySelectorAll(".btr_title").length > 0)
  186. continue;
  187.  
  188. let _title = _titlesDiv[i].querySelectorAll("h3, a.title");
  189.  
  190. if (this.Debug)
  191. console.log(_title);
  192.  
  193. if (this.btr_pTitle == true)
  194. {
  195. let lengthOfIndexes = 0;
  196.  
  197. this.ChangeString(_title[0].textContent.length, _title[0].textContent, _title[0], lengthOfIndexes);
  198. }
  199. else if (this.asterisk == true)
  200. {
  201. let lengthOfIndexes = this.GetAllIndexes(_title[0].textContent, "[", "(").length;
  202.  
  203. lengthOfIndexes += this.GetAllIndexes(_title[0].textContent, "*", "even").length;
  204.  
  205. this.ChangeString(_title[0].textContent.length, _title[0].textContent, _title[0], lengthOfIndexes);
  206. } else
  207. {
  208. let lengthOfIndexes = this.GetAllIndexes(_title[0].textContent, "[", "(").length;
  209.  
  210. this.ChangeString(_title[0].textContent.length, _title[0].textContent, _title[0], lengthOfIndexes);
  211. }
  212. }
  213. }
  214. }
  215.  
  216. ChangeString(l, sArr, tTitle, amountL)
  217. {
  218. const stringStartbdi = '<bdi class = "btr_main btr_title btr_trans">',
  219. stringEndbdi = '</bdi>';
  220.  
  221. let amount = amountL;
  222.  
  223. let string = "";
  224.  
  225. if (amount > 3)
  226. amount = 1;
  227.  
  228. let arrBeg = this.GetAllIndexes(sArr, "[", "(");
  229. let arrEnd = this.GetAllIndexes(sArr, "]", ")");
  230.  
  231. if (this.asterisk === true)
  232. {
  233. arrBeg = arrBeg.concat(this.GetAllIndexes(sArr, "*", "even"));
  234. arrEnd = arrEnd.concat(this.GetAllIndexes(sArr, "*", "odd"));
  235. }
  236.  
  237. arrBeg.sort(function (a, b)
  238. {
  239. return a - b;
  240. });
  241.  
  242. arrEnd.sort(function (a, b)
  243. {
  244. return a - b;
  245. });
  246.  
  247. if (amount === 0)
  248. {
  249. string = stringStartbdi + ' ' + sArr + ' ' + stringEndbdi;
  250. if (this.Debug)
  251. {
  252. console.info(string);
  253. }
  254. tTitle.innerHTML = string;
  255. return;
  256. }
  257.  
  258. if (amount === 1)
  259. {
  260. if (this.Debug)
  261. {
  262. console.log("*words in brackets :", sArr.substring(arrBeg[0], arrEnd[0] + 1));
  263. }
  264. //IF WHOLE TITLE IN BRACKETS
  265. if (arrBeg[0] <= 2 && arrEnd[0] >= l - 2)
  266. {
  267. string = stringStartbdi + ' ' + sArr + ' ' + stringEndbdi;
  268. if (this.Debug)
  269. {
  270. console.info(string);
  271. }
  272. tTitle.innerHTML = string;
  273. return;
  274. }
  275.  
  276. if (arrBeg[0] <= 2)
  277. {
  278. string = sArr.substring(arrBeg[0], arrEnd[0] + 1) + ' ' + stringStartbdi + ' ' + sArr.substring(arrEnd[0] + 1, l) + ' ' + stringEndbdi;
  279. if (this.Debug)
  280. {
  281. console.info(string);
  282. }
  283. tTitle.innerHTML = string;
  284. return;
  285. } else if (arrEnd[0] >= l - 2)
  286. {
  287. string = stringStartbdi + ' ' + sArr.substring(0, arrBeg[0]) + ' ' + stringEndbdi + ' ' + sArr.substring(arrBeg[0], l);
  288. if (this.Debug)
  289. {
  290. console.info(string);
  291. }
  292. tTitle.innerHTML = string;
  293. return;
  294. } else
  295. {
  296. string = stringStartbdi + ' ' + sArr.substring(0, arrBeg[0]) + ' ' + stringEndbdi + ' ' + sArr.substring(arrBeg[0], arrEnd[0] + 1) + ' ' + stringStartbdi + ' ' + sArr.substring(arrEnd[0] + 1, l) + ' ' + stringEndbdi;
  297. if (this.Debug)
  298. {
  299. console.info(string);
  300. }
  301. tTitle.innerHTML = string;
  302. return;
  303. }
  304. }
  305.  
  306. if (amount === 2)
  307. {
  308. let s = '';
  309. for (let a = 0; a < arrBeg.length; a++)
  310. {
  311. s += sArr.substring(arrBeg[a], arrEnd[a] + 1) + ' ';
  312. }
  313. if (this.Debug)
  314. {
  315. console.log("*words in brackets :", s);
  316. }
  317.  
  318. //IF TITLE HAS ONE BRACKET WITHOUT CLOSING ONE
  319. if (arrBeg.length !== arrEnd.length)
  320. {
  321. ChangeString(l, sArr, tTitle, 1);
  322. return;
  323. }
  324.  
  325. //IF WHOLE TITLE IN BRACKETS, NOT WORKING CORRECTLY TODO!
  326. if ((arrBeg[0] <= 2 && arrEnd[0] >= l - 2) || (arrBeg[1] <= 2 && arrEnd[1] >= l - 2))
  327. {
  328. string = stringStartbdi + ' ' + sArr + ' ' + stringEndbdi;
  329. if (this.Debug)
  330. {
  331. console.info(string);
  332. }
  333. tTitle.innerHTML = string;
  334. return;
  335. }
  336.  
  337. if (arrBeg[0] <= 2)
  338. {
  339. if (arrEnd[0] + 4 > arrBeg[1])
  340. {
  341. string = sArr.substring(arrBeg[0], arrEnd[1] + 1) + ' ' + stringStartbdi + ' ' + sArr.substring(arrEnd[1] + 1, l) + ' ' + stringEndbdi;
  342. if (this.Debug)
  343. {
  344. console.info(string);
  345. }
  346. tTitle.innerHTML = string;
  347. return;
  348. } else if (arrEnd[1] >= l - 2)
  349. {
  350. string = sArr.substring(arrBeg[0], arrEnd[0] + 1) + ' ' + stringStartbdi + ' ' + sArr.substring(arrEnd[0] + 1, arrBeg[1]) + ' ' + stringEndbdi + ' ' + sArr.substring(arrBeg[1], l);
  351. if (this.Debug)
  352. {
  353. console.info(string);
  354. }
  355. tTitle.innerHTML = string;
  356. return;
  357. } else
  358. {
  359. string = sArr.substring(arrBeg[0], arrEnd[0] + 1) + ' ' + stringStartbdi + ' ' + sArr.substring(arrEnd[0] + 1, arrBeg[1]) + ' ' + stringEndbdi + ' ' + sArr.substring(arrBeg[1], arrEnd[1] + 1) + ' ' + stringStartbdi + ' ' + sArr.substring(arrEnd[1] + 1, l) + ' ' + stringEndbdi;
  360. if (this.Debug)
  361. {
  362. console.info(string);
  363. }
  364. tTitle.innerHTML = string;
  365. return;
  366. }
  367. } else if (arrEnd[1] >= l - 2)
  368. {
  369. if (arrBeg[1] - 4 < arrEnd[0])
  370. {
  371. string = stringStartbdi + ' ' + sArr.substring(0, arrBeg[0]) + ' ' + stringEndbdi + ' ' + sArr.substring(arrBeg[0], l);
  372. if (this.Debug)
  373. {
  374. console.info(string);
  375. }
  376. tTitle.innerHTML = string;
  377. return;
  378. } else if (arrBeg[0] <= 2)
  379. {
  380. string = sArr.substring(arrBeg[0], arrEnd[0] + 1) + ' ' + stringStartbdi + ' ' + sArr.substring(arrEnd[0] + 1, arrBeg[1]) + ' ' + stringEndbdi + ' ' + sArr.substring(arrBeg[1], l);
  381. if (this.Debug)
  382. {
  383. console.info(string);
  384. }
  385. tTitle.innerHTML = string;
  386. return;
  387. } else
  388. {
  389. string = stringStartbdi + ' ' + sArr.substring(0, arrBeg[0]) + ' ' + stringEndbdi + ' ' + sArr.substring(arrBeg[0], arrEnd[0] + 1) + ' ' + stringStartbdi + ' ' + sArr.substring(arrEnd[0] + 1, arrBeg[1]) + ' ' + stringEndbdi + ' ' + sArr.substring(arrBeg[1], l);
  390. if (this.Debug)
  391. {
  392. console.info(string);
  393. }
  394. tTitle.innerHTML = string;
  395. return;
  396. }
  397. } else
  398. {
  399. if (arrEnd[0] + 3 >= arrBeg[1])
  400. {
  401. string = stringStartbdi + ' ' + sArr.substring(0, arrBeg[0]) + ' ' + stringEndbdi + ' ' + sArr.substring(arrBeg[0], arrEnd[1] + 1) + ' ' + stringStartbdi + ' ' + sArr.substring(arrEnd[1] + 1, l) + ' ' + stringEndbdi;
  402. if (this.Debug)
  403. {
  404. console.info(string);
  405. }
  406. tTitle.innerHTML = string;
  407. return;
  408. } else
  409. {
  410. string = stringStartbdi + ' ' + sArr.substring(0, arrBeg[0]) + ' ' + stringEndbdi + ' ' + sArr.substring(arrBeg[0], arrEnd[0] + 1) + ' ' + stringStartbdi + ' ' + sArr.substring(arrEnd[0] + 1, arrBeg[1]) + ' ' + stringEndbdi + ' ' + sArr.substring(arrBeg[1], arrEnd[1] + 1) + ' ' + stringStartbdi + ' ' + sArr.substring(arrEnd[1] + 1, l) + ' ' + stringEndbdi;
  411. if (this.Debug)
  412. {
  413. console.info(string);
  414. }
  415. tTitle.innerHTML = string;
  416. return;
  417. }
  418. }
  419. }
  420.  
  421. //Three groups of brackets
  422. //example sentence: "[spoiler0]_text1_[spoiler1]_text2_[spoiler2]"
  423. if (amount === 3)
  424. {
  425. let s = '';
  426. for (let a = 0; a < arrBeg.length; a++)
  427. {
  428. s += sArr.substring(arrBeg[a], arrEnd[a] + 1) + ' ';
  429. }
  430. if (this.Debug)
  431. {
  432. console.log("*words in brackets :", s);
  433. }
  434.  
  435. //IF TITLE HAS ONE BRACKET WITHOUT CLOSING ONE
  436. if (arrBeg.length !== arrEnd.length)
  437. {
  438. ChangeString(l, sArr, tTitle, 1);
  439. return;
  440. }
  441.  
  442. //IF WHOLE TITLE IN BRACKETS, NOT WORKING CORRECTLY TODO!
  443. if ((arrBeg[0] <= 2 && arrEnd[0] >= l - 2) || (arrBeg[1] <= 2 && arrEnd[1] >= l - 2) || (arrBeg[2] <= 2 && arrEnd[2] >= l - 2))
  444. {
  445. string = stringStartbdi + ' ' + sArr + ' ' + stringEndbdi;
  446. if (this.Debug)
  447. {
  448. console.info(string);
  449. }
  450. tTitle.innerHTML = string;
  451. return;
  452. }
  453.  
  454. //case one:"[spoiler0]..."
  455. if (arrBeg[0] <= 2)
  456. {
  457. //case one:one:"[spoiler0][spoiler1]..."
  458. if (arrEnd[0] + 4 > arrBeg[1])
  459. {
  460. //case one:one:one:"[spoiler0][spoiler1][spoiler2]_text"
  461. if (arrEnd[1] + 4 > arrBeg[2])
  462. {
  463. //"[spoiler0][spoiler1][spoiler2]<blur>text</blur>"
  464. string = sArr.substring(arrBeg[0], arrEnd[2] + 1) + ' ' + stringStartbdi + ' ' + sArr.substring(arrEnd[2] + 1, l) + ' ' + stringEndbdi;
  465. if (this.Debug)
  466. {
  467. console.info(string);
  468. }
  469. tTitle.innerHTML = string;
  470. return;
  471. //case one:one:two:"[spoiler0][spoiler1]_text_[spoiler2]"
  472. } else if (arrEnd[2] >= l - 2)
  473. {
  474. //"[spoiler0][spoiler1]<blur>text</blur>[spoiler2]"
  475. string = sArr.substring(arrBeg[0], arrEnd[1] + 1) + ' ' + stringStartbdi + ' ' + sArr.substring(arrEnd[1] + 1, arrBeg[2]) + ' ' + stringEndbdi + ' ' + sArr.substring(arrBeg[2], l);
  476. if (this.Debug)
  477. {
  478. console.info(string);
  479. }
  480. tTitle.innerHTML = string;
  481. return;
  482. //case one:one:three:"[spoiler0][spoiler1]_text1_[spoiler2]_text2"
  483. } else
  484. {
  485. //"[spoiler0][spoiler1]<blur>text1</blur>[spoiler2]<blur>text2</blur>"
  486. string = sArr.substring(arrBeg[0], arrEnd[1] + 1) + ' ' + stringStartbdi + ' ' + sArr.substring(arrEnd[1] + 1, arrBeg[2]) + ' ' + stringEndbdi + ' ' + sArr.substring(arrBeg[2], arrEnd[2] + 1) + ' ' + stringStartbdi + ' ' + sArr.substring(arrEnd[2] + 1, l) + ' ' + stringEndbdi;
  487. if (this.Debug)
  488. {
  489. console.info(string);
  490. }
  491. tTitle.innerHTML = string;
  492. return;
  493. }
  494. //case one:two:"[spoiler0]...[spoiler2]"
  495. //"[spoiler0]...[spoiler1]":NEVER HAPPEND
  496. } else if (arrEnd[2] >= l - 2)
  497. {
  498. //case one:two:one:"[spoiler0]_text_[spoiler1][spoiler2]"
  499. if (arrEnd[1] + 4 > arrBeg[2])
  500. {
  501. //"[spoiler0]<blur>text</blur>[spoiler1][spoiler2]"
  502. string = sArr.substring(arrBeg[0], arrEnd[0] + 1) + ' ' + stringStartbdi + ' ' + sArr.substring(arrEnd[0] + 1, arrBeg[1]) + ' ' + stringEndbdi + ' ' + sArr.substring(arrBeg[1], l);
  503. if (this.Debug)
  504. {
  505. console.info(string);
  506. }
  507. tTitle.innerHTML = string;
  508. return;
  509. }
  510. //case one:two:two:"[spoiler0]_text1_[spoiler1]_text2_[spoiler2]"
  511. else
  512. {
  513. //"[spoiler0]<blur>text1</blur>[spoiler1]<blur>text2</blur>[spoiler2]"
  514. string = sArr.substring(arrBeg[0], arrEnd[0] + 1) + ' ' + stringStartbdi + ' ' + sArr.substring(arrEnd[0] + 1, arrBeg[1]) + ' ' + stringEndbdi + ' ' + sArr.substring(arrBeg[1], arrEnd[1] + 1) + ' ' + stringStartbdi + ' ' + sArr.substring(arrEnd[1] + 1, arrBeg[2]) + ' ' + stringEndbdi + ' ' + sArr.substring(arrBeg[2], l);
  515. if (this.Debug)
  516. {
  517. console.info(string);
  518. }
  519. tTitle.innerHTML = string;
  520. return;
  521. }
  522. //case one:three:"[spoiler0]_text1_[spoiler1]_text2_[spoiler2]_text3"
  523. } else
  524. {
  525. //"[spoiler0]<blur>text1</blur>[spoiler1]<blur>text2</blur>[spoiler2]<blur>text3</blur>"
  526. string = sArr.substring(arrBeg[0], arrEnd[0] + 1) + ' ' + stringStartbdi + ' ' + sArr.substring(arrEnd[0] + 1, arrBeg[1]) + ' ' + stringEndbdi + ' ' + sArr.substring(arrBeg[1], arrEnd[1] + 1) + ' ' + stringStartbdi + ' ' + sArr.substring(arrEnd[1] + 1, arrBeg[2]) + ' ' + stringEndbdi + ' ' + sArr.substring(arrBeg[2], arrEnd[2] + 1) + ' ' + stringStartbdi + ' ' + sArr.substring(arrEnd[2] + 1, l) + ' ' + stringEndbdi;
  527. if (this.Debug)
  528. {
  529. console.info(string);
  530. }
  531. tTitle.innerHTML = string;
  532. return;
  533. }
  534. //case two:"...[spoiler2]"
  535. } else if (arrEnd[2] >= l - 2)
  536. {
  537. //case two:one:"...[spoiler1][spoiler2]"
  538. if (arrEnd[1] + 4 > arrBeg[2])
  539. {
  540. //case two:one:one:"text_[spoiler0][spoiler1][spoiler2]"
  541. if (arrEnd[0] + 4 > arrBeg[1])
  542. {
  543. //"<blur>text</blur>[spoiler0][spoiler1][spoiler2]"
  544. string = stringStartbdi + ' ' + sArr.substring(0, arrBeg[0]) + ' ' + stringEndbdi + ' ' + sArr.substring(arrBeg[0], l);
  545. if (this.Debug)
  546. {
  547. console.info(string);
  548. }
  549. tTitle.innerHTML = string;
  550. return;
  551. //case two:one:one:"text1_[spoiler0]_text2_[spoiler1][spoiler2]"
  552. //"[spoiler0]_text_[spoiler1][spoiler2]":NEVER HAPPEND
  553. } else
  554. {
  555. //"<blur>text1</blur>[spoiler0]<blur>text2</blur>[spoiler1][spoiler2]"
  556. string = stringStartbdi + ' ' + sArr.substring(0, arrBeg[0]) + ' ' + stringEndbdi + ' ' + sArr.substring(arrBeg[0], arrEnd[0] + 1) + ' ' + stringStartbdi + ' ' + sArr.substring(arrEnd[0] + 1, arrBeg[1]) + ' ' + stringEndbdi + ' ' + sArr.substring(arrEnd[1] + 1, l);
  557. if (this.Debug)
  558. {
  559. console.info(string);
  560. }
  561. tTitle.innerHTML = string;
  562. return;
  563. }
  564. //case two:two:"text1_[spoiler0][spoiler1]_text2_[spoiler2]"
  565. } else if (arrEnd[0] + 4 > arrBeg[1])
  566. {
  567. //"<blur>text1</blur>[spoiler0][spoiler1]<blur>text2</blur>[spoiler2]"
  568. string = stringStartbdi + ' ' + sArr.substring(0, arrBeg[0]) + ' ' + stringEndbdi + ' ' + sArr.substring(arrBeg[0], arrEnd[1] + 1) + ' ' + stringStartbdi + ' ' + sArr.substring(arrEnd[1] + 1, arrBeg[2]) + ' ' + stringEndbdi + ' ' + sArr.substring(arrEnd[2] + 1, l);
  569. if (this.Debug)
  570. {
  571. console.info(string);
  572. }
  573. tTitle.innerHTML = string;
  574. return;
  575. //case two:two:"text1_[spoiler0]_text2_[spoiler1]_text3_[spoiler2]"
  576. } else
  577. {
  578. //"<blur>text1</blur>[spoiler0]<blur>text2</blur>[spoiler1]<blur>text3</blur>[spoiler2]"
  579. string = stringStartbdi + ' ' + sArr.substring(0, arrBeg[0]) + ' ' + stringEndbdi + ' ' + sArr.substring(arrBeg[0], arrEnd[0] + 1) + ' ' + stringStartbdi + ' ' + sArr.substring(arrEnd[0] + 1, arrBeg[1]) + ' ' + stringEndbdi + ' ' + sArr.substring(arrBeg[1], arrEnd[1] + 1) + ' ' + stringStartbdi + ' ' + sArr.substring(arrEnd[1] + 1, arrBeg[2]) + ' ' + stringEndbdi + ' ' + sArr.substring(arrBeg[2], l);
  580. if (this.Debug)
  581. {
  582. console.info(string);
  583. }
  584. tTitle.innerHTML = string;
  585. return;
  586. }
  587. //case three:"text1_[spoiler0]_text2_[spoiler1]_text3_[spoiler2]_text4"
  588. //DO I NEED ALL CASES??? TODO!
  589. } else
  590. {
  591. //"<blur>text1</blur>[spoiler0]<blur>text2</blur>[spoiler1]<blur>text3</blur>[spoiler2]<blur>text4</blur>"
  592. string = stringStartbdi + ' ' + sArr.substring(0, arrBeg[0]) + ' ' + stringEndbdi + ' ' + sArr.substring(arrBeg[0], arrEnd[0] + 1) + ' ' + stringStartbdi + ' ' + sArr.substring(arrEnd[0] + 1, arrBeg[1]) + ' ' + stringEndbdi + ' ' + sArr.substring(arrBeg[1], arrEnd[1] + 1) + ' ' + stringStartbdi + ' ' + sArr.substring(arrEnd[1] + 1, arrBeg[2]) + ' ' + stringEndbdi + ' ' + sArr.substring(arrBeg[2], arrEnd[2] + 1) + ' ' + stringStartbdi + ' ' + sArr.substring(arrEnd[2] + 1, l) + ' ' + stringEndbdi;
  593. if (this.Debug)
  594. {
  595. console.info(string);
  596. }
  597. tTitle.innerHTML = string;
  598. return;
  599. }
  600.  
  601. }
  602. }
  603.  
  604. //second value can be "even" or "odd"
  605. GetAllIndexes(arr, val1, val2)
  606. {
  607. let indexes = [], temp = [], x, i;
  608. switch (val2)
  609. {
  610. case "even":
  611. for (x = 0; x < arr.length; x++)
  612. if (arr[x] === val1)
  613. temp.push(x);
  614. for (i = 0; i < temp.length; i++)
  615. {
  616. if (this.IsEven(i))
  617. {
  618. indexes.push(temp[i]);
  619. }
  620. }
  621. break;
  622. case "odd":
  623. for (x = 0; x < arr.length; x++)
  624. if (arr[x] === val1)
  625. temp.push(x);
  626. for (i = 0; i < temp.length; i++)
  627. {
  628. if (!this.IsEven(i))
  629. {
  630. indexes.push(temp[i]);
  631. }
  632. }
  633. break;
  634. default:
  635. for (x = 0; x < arr.length; x++)
  636. if (arr[x] === val1 || arr[x] === val2)
  637. indexes.push(x);
  638. break;
  639. }
  640. return indexes;
  641. }
  642.  
  643. IsEven(n)
  644. {
  645. return n === parseFloat(n) ? !(n % 2) : void 0;
  646. }
  647.  
  648. OptionsUI()
  649. {
  650. document.body.insertAdjacentHTML("beforeend", `<div id=btrSettings class='side jAyrXr'><div class=spaser ><div class=sidecontentbox><span class=btr_closeButton>&times</span> \
  651. <div class=title><h1>Settings of Blur Title Reddit` + GM.info.script.version + `</h1></div>\
  652. <ul class=content><li> \
  653. <form> \
  654. <br> \
  655. <p>Bluring option:</p>\
  656. <input type=radio name=title id=btr_showTitle >Show brackets</input><br> \
  657. <input type=radio name=title id=btr_hideTitle >Hide brackets</input><br><br> \
  658. <input type=checkbox name=asterisk id=asterisk >Show what between asterisks like brackets</input><br><br> \
  659. <input type=checkbox name=debug id=debug >Debug</input><br> \
  660. </form> <br> \
  661. <button id=btr_hide class=hauwm>Hide Settings</button></li></ul></div></div></div>`);
  662.  
  663.  
  664. //SET UI SETTINGS
  665. document.getElementById("debug").setAttribute("checked", this.Debug);
  666. document.getElementById("asterisk").setAttribute("checked", this.asterisk);
  667.  
  668. if (this.btr_pTitle === true)
  669. {
  670. document.getElementById("btr_hideTitle").setAttribute("checked", true);
  671. } else
  672. {
  673. document.getElementById("btr_showTitle").setAttribute("checked", true);
  674. }
  675.  
  676. document.getElementById("btrSettings").style.display = "none";
  677.  
  678. //CHANGE SETTINGS BY INTERACT WITH UI
  679. document.getElementById("debug").addEventListener("click", async (e) =>
  680. {
  681. if (btr.Debug === true)
  682. {
  683. GM.setValue("btr_debug", false);
  684. btr.Debug = await GM.getValue("btr_debug");
  685. } else
  686. {
  687. GM.setValue("btr_debug", true);
  688. btr.Debug = await GM.getValue("btr_debug");
  689. }
  690.  
  691. confirm("Settings has been changed.");
  692. if (btr.Debug)
  693. {
  694. console.log('debug: ' + await GM.getValue("btr_debug") + ' and debug: ' + btr.Debug);
  695. }
  696. });
  697.  
  698. document.getElementById("asterisk").addEventListener("click", async (e) =>
  699. {
  700. if (btr.asterisk === true)
  701. {
  702. GM.setValue("btr_asterisk", false);
  703. btr.asterisk = await GM.getValue("btr_asterisk");
  704. } else
  705. {
  706. GM.setValue("btr_asterisk", true);
  707. btr.asterisk = await GM.getValue("btr_asterisk");
  708. }
  709.  
  710. confirm("Settings has been changed.");
  711. if (btr.Debug)
  712. {
  713. console.log('btr_asterisk: ' + await GM.getValue("btr_asterisk") + ' and asterisk: ' + btr.asterisk);
  714. }
  715. });
  716.  
  717. /* TODO!
  718. document.getElementById("#btr_showTitle").onclick((e) =>
  719. {
  720. GM.setValue("btr_GMTitle", false);
  721. btr_pTitle = await GM.getValue("btr_GMTitle");
  722. ReplaceOriginalTitles();
  723. MyFunction();
  724. alert("Settings has been changed. Now brackets showing.");
  725. if (debug)
  726. {
  727. console.log('btr_GMTitle: ' + await GM.getValue("btr_GMTitle") + ' and btr_pTitle: ' + btr_pTitle);
  728. }
  729. });
  730.  
  731. $("#btr_hideTitle").change(async function ()
  732. {
  733. GM.setValue("btr_GMTitle", true);
  734. btr_pTitle = await GM.getValue("btr_GMTitle");
  735. ReplaceOriginalTitles();
  736. MyFunction();
  737. alert("Settings has been changed. Now brackets hiding.");
  738. if (debug)
  739. {
  740. console.log('btr_GMTitle: ' + await GM.getValue("btr_GMTitle") + ' and btr_pTitle: ' + btr_pTitle);
  741. }
  742. });
  743. */
  744.  
  745. //TODO ???
  746. //$(".side").append("<div class=spacer><div class=sidecontentbox><div class=title><h1>BLUR TITLE REDDIT</h1></div><ul class=content><li><button id=btr_show >Show settings</button></li></ul></div></div>");
  747. //console.log(currentLocation.pathname);
  748. //if (currentLocation.pathname === "/r/Steam")
  749. //{
  750. // $(".debuginfo").after("<p><a id=btr_show style={float=right;}>show settings blur title reddit</a></p>");
  751. //} else {
  752. //$(".side").append("<div class=spacer><div class=account-activity-box><p><a id=btr_show >show settings blur title reddit</a></p></div></div>");
  753. //}
  754.  
  755. document.querySelector("div[data-testid='subreddit-sidebar'], div.side").insertAdjacentHTML("beforeend", `<div class=spacer><div class=account-activity-box style=cursor:pointer;><p><a id=btr_show >show settings for blur title reddit</a></p></div></div>`);
  756.  
  757. document.getElementById("btr_hide").addEventListener("click", (e) =>
  758. {
  759. document.getElementById("btrSettings").style.display = "none";
  760. });
  761.  
  762. document.querySelector(".btr_closeButton").addEventListener("click", (e) =>
  763. {
  764. document.getElementById("btrSettings").style.display = "none";
  765. });
  766.  
  767. document.getElementById("btr_show").addEventListener("click", (e) =>
  768. {
  769. document.getElementById("btrSettings").style.display = "block";
  770.  
  771. if (!document.getElementById("btrSettings").classList.contains("btr_opt"))
  772. document.getElementById("btrSettings").className += " btr_opt";
  773. });
  774. }
  775.  
  776. //Start
  777. //async Methods/Functions GM_VALUE
  778. async HasValueGM(nameVal, optValue)
  779. {
  780. let vals = await GM.listValues();
  781.  
  782. if (vals.length === 0)
  783. {
  784. if (optValue !== undefined)
  785. {
  786. GM.setValue(nameVal, optValue);
  787. return true;
  788. } else
  789. {
  790. return false;
  791. }
  792. }
  793.  
  794. if (typeof nameVal !== "string")
  795. {
  796. return alert("name of value: '" + nameVal + "' are not string");
  797. }
  798.  
  799. for (let i = 0; i < vals.length; i++)
  800. {
  801. if (vals[i] === nameVal)
  802. {
  803. return true;
  804. }
  805. }
  806.  
  807. if (optValue !== undefined)
  808. {
  809. GM.setValue(nameVal, optValue);
  810. return true;
  811. } else
  812. {
  813. return false;
  814. }
  815. }
  816. async DeleteValuesGM(nameVal)
  817. {
  818. let vals = await GM.listValues();
  819.  
  820. if (vals.length === 0 || typeof nameVal !== "string")
  821. {
  822. return;
  823. }
  824.  
  825. switch (nameVal)
  826. {
  827. case "all":
  828. for (let i = 0; i < vals.length; i++)
  829. {
  830. if (vals[i] !== "adm")
  831. {
  832. GM.deleteValue(vals[i]);
  833. }
  834. }
  835. break;
  836. case "old":
  837. for (let i = 0; i < vals.length; i++)
  838. {
  839. if (vals[i] === "debug" || vals[i] === "debugA")
  840. {
  841. GM.deleteValue(vals[i]);
  842. }
  843. }
  844. break;
  845. default:
  846. for (let i = 0; i < vals.length; i++)
  847. {
  848. if (vals[i] === nameVal)
  849. {
  850. GM.deleteValue(nameVal);
  851. }
  852. }
  853. break;
  854. }
  855. }
  856. async UpdateGM(what)
  857. {
  858. var gmVal;
  859.  
  860. switch (what)
  861. {
  862. case "options":
  863. gmVal = JSON.stringify(options.values);
  864. GM.setValue("pp_options", gmVal);
  865. break;
  866. default:
  867. alert("class:Options.UpdateGM(" + what + "). default switch");
  868. break;
  869. }
  870. }
  871. //async Methods/Functions GM_VALUE
  872. //End
  873. }
  874.  
  875. let btr;
  876.  
  877. window.onload = function ()
  878. {
  879. btr = new BlurTitleReddit();
  880.  
  881. setTimeout(() =>
  882. {
  883. btr.Main();
  884. console.log(btr);
  885. }, 1000);
  886. };