Anime Website Buttons Plus

A script that adds buttons on Anime Planet, MAL and Anilist for searching various sites.

当前为 2020-03-25 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @author Deathwing
  3. // @name Anime Website Buttons Plus
  4. // @include https://www.anime-planet.com/anime/*
  5. // @include http://myanimelist.net/anime/*
  6. // @include https://myanimelist.net/anime/*
  7. // @include https://anilist.co/anime/*
  8. // @exclude https://www.anime-planet.com/anime/
  9. // @exclude https://www.anime-planet.com/anime/all?name=*
  10. // @exclude https://www.anime-planet.com/anime/recommendations/*
  11. // @description A script that adds buttons on Anime Planet, MAL and Anilist for searching various sites.
  12. // @version 2.051
  13. // @grant GM.setValue
  14. // @grant GM.getValue
  15. // @grant GM.listValues
  16. // @grant GM.deleteValue
  17. // @namespace https://greasyfork.org/users/18375
  18. // ==/UserScript==
  19.  
  20.  
  21. //Find h1
  22. var header;
  23. var host = document.location.host;
  24. var malHost = 'myanimelist.net';
  25. var apHost = 'www.anime-planet.com';
  26. var alHost = 'anilist.co';
  27.  
  28. if (host === apHost) {
  29. header = getHeader("#siteContainer h1");
  30. main();
  31. }
  32. else if (host === malHost) {
  33. header = getHeader('#contentWrapper span span');
  34. main();
  35. }
  36. else if (host === alHost) {
  37. function getAlHeader() {
  38.  
  39. header = getHeader('div.content h1');
  40.  
  41. if (header) {
  42. main();
  43. }
  44. else {
  45. setTimeout(getAlHeader, 500);
  46. }
  47. }
  48.  
  49. getAlHeader();
  50. }
  51.  
  52. function getHeader(atr) {
  53. return document.querySelector(atr);
  54. }
  55.  
  56.  
  57. var hideList = [];
  58.  
  59. function main() {
  60.  
  61. //Cut anime name
  62. var animeName;
  63.  
  64. if (host === apHost) {
  65. animeName = getAnimeName();
  66. }
  67. else if (host === malHost) {
  68. animeName = header.childNodes[0].nodeValue;
  69. }
  70. else if (host === alHost) {
  71. animeName = getAnimeName();
  72. }
  73.  
  74.  
  75. function getAnimeName() {
  76. return header.textContent.trim();
  77. }
  78.  
  79.  
  80. function creteButton(icon, searchUrl, title) {
  81. var buttImg = createHTMLElement("img", null, null, [{ n: 'style', v: 'width:16px;height:16px;margin-right:2px;' }, { n: 'src', v: icon }]);
  82. var button = createHTMLElement("a", null, 'animeButton', [{ n: 'id', v: `animeButton${makeButtonId(title)}` },
  83. { n: 'href', v: searchUrl }, { n: 'target', v: "_blank" }, { n: 'title', v: title }]);
  84. button.appendChild(buttImg);
  85. return button;
  86. }
  87.  
  88. //Set buttons with information
  89.  
  90. var buttonCounter = 0;
  91.  
  92. //MAL Button
  93. var icon = 'https://myanimelist.net/favicon.ico';
  94. var searchUrl = 'http://myanimelist.net/anime.php?q=' + animeName;
  95. var title = "Search MyAnimeList";
  96.  
  97. var malButton = creteButton(icon, searchUrl, title);
  98.  
  99.  
  100. //Anilist Button
  101. icon = 'https://www.google.com/s2/favicons?domain=anilist.co';
  102. searchUrl = 'https://anilist.co/search/anime?search=' + animeName + '&sort=SEARCH_MATCH';
  103. title = "Search Anilist";
  104.  
  105. var alButton = creteButton(icon, searchUrl, title);
  106.  
  107.  
  108. //Anime-Planet Button
  109. icon = 'https://www.anime-planet.com/favicon.ico';
  110. searchUrl = 'https://www.anime-planet.com/anime/all?name=' + animeName;
  111. title = "Search Anime-Planet";
  112.  
  113. var apButton = creteButton(icon, searchUrl, title);
  114.  
  115.  
  116. //YouTube Button
  117. icon = 'https://www.google.com/s2/favicons?domain=youtube.com';
  118. searchUrl = 'https://www.youtube.com/results?search_query=' + animeName + " trailer";
  119. title = 'YouTube Trailer';
  120.  
  121. var ytButton = creteButton(icon, searchUrl, title);
  122.  
  123.  
  124. //Google Images button
  125. icon = 'https://www.google.com/s2/favicons?domain=www.google.com/';
  126. searchUrl = 'https://www.google.bg/search?tbm=isch&biw=&bih=&gbv=2&q=' + animeName;
  127. title = "Search with Google Images";
  128.  
  129. var giButton = creteButton(icon, searchUrl, title);
  130.  
  131.  
  132. //Nyaa button
  133. icon = 'https://www.google.com/s2/favicons?domain=nyaa.si/';
  134. searchUrl = 'https://nyaa.si/?f=0&c=0_0&q=' + animeName;
  135. title = "Search Nyaa";
  136.  
  137. var nyButton = creteButton(icon, searchUrl, title);
  138. header.addEventListener('mouseover', showEditButton);
  139. header.addEventListener('mouseout', hideEditButton);
  140.  
  141.  
  142. //Edit button
  143. icon = 'https://previews.dropbox.com/p/thumb/AAs_uEIlA0XGqQKA3-9SaVvSNTEfLD9T59ZRlYGPzHmrabhLYbrFL_7v07jrFvFwmHhfCyYTmwFjeC-00XVF7LE4zkSnA7q1f_dvUrhH-M9rDEL7ZaqzQLC_2lO3oxevjm235o8NS3R3-fBVijSrtHcdKgG_0B3FnCEYM5LHkvZO6P0HbrQQ2gmwo4m4JE4EbD44oSCMXcGqy0kU5kzBtKFgbP57Cv-k9HHw3SnNNsFiPC9HGRIiYA9PhCAjxFzy8gRFJlWwR5V7iIJJq9-ImQ_FLxlX_bn27k7IexLJvWHaf4UmK3nifCisIb0oMVUeyBfBhXd04kIVfmwFnwXgjnud/p.png?size=2048x1536&size_mode=3';
  144. title = "Edit Custom Buttons";
  145.  
  146. var editButtonImg = createHTMLElement('img', null, 'editButton', [{ n: 'src', v: icon }, { n: 'title', v: title },
  147. { n: 'style', v: 'width:16px;height:16px;display:none;' }]);
  148. var editButton = createHTMLElement('div', null, null, [{ n: 'style', v: 'width:16px;height:16px;margin-right:2px;display:inline;padding-right:16px;' }]);
  149. editButton.appendChild(editButtonImg);
  150.  
  151. editButton.addEventListener('click', editButtonHandler);
  152.  
  153.  
  154. const customButtons = [];
  155. const customButtonsObj = [];
  156.  
  157. var valuesListPromise = GM.listValues();
  158. valuesListPromise.then(getCustomButtons);
  159.  
  160. function appendCustomButtons(customButtonsObj) {
  161. customButtonsObj.forEach((b) => {
  162. customButtons.push(creteButton(b.icon, b.url.replace('ANIMENAME', animeName), b.title));
  163. })
  164. startAppending();
  165. }
  166.  
  167.  
  168. //Add Website Buttons
  169. function startAppending() {
  170. if (host === apHost) {
  171. appendButtons([malButton, alButton]);
  172. }
  173. else if (host === alHost) {
  174. appendButtons([malButton, apButton]);
  175. }
  176. else if (host === malHost) {
  177. appendButtons([apButton, alButton]);
  178. }
  179. }
  180.  
  181. function appendButtons(buttonsArray) {
  182. header.appendChild(document.createTextNode(" "));
  183.  
  184. const otherButtons = [ytButton, giButton, nyButton];
  185. const allButtons = buttonsArray.concat(otherButtons, customButtons, editButton);
  186.  
  187. allButtons.forEach((b) => {
  188. if (b.id !== '') {
  189. hideList.push({ bId: b.id, h: 'show' })
  190. }
  191. });
  192.  
  193. getHideList();
  194. appendChildren(header, allButtons);
  195. }
  196.  
  197. function getHideList() {
  198. var promise = GM.getValue('hideList', '[]');
  199.  
  200. promise.then((v) => {
  201. var localVal = JSON.parse(v);
  202.  
  203. concatHideList(localVal);
  204. hideButtons();
  205. addButtonPopup();
  206. });
  207. }
  208.  
  209. function concatHideList(v) {
  210. v.forEach(b => {
  211. var item = hideList.find(n => n.bId === b.bId);
  212. if (item) { return Object.assign(item, b); }
  213. hideList.push(b);
  214. });
  215. }
  216.  
  217.  
  218. function getCustomButtons(values) {
  219. values.forEach(async (n) => {
  220. if (n !== 'hideList') {
  221. customButtonsObj.push(JSON.parse(await GM.getValue(n)));
  222. }
  223. });
  224.  
  225. checkIfDataReady();
  226. }
  227.  
  228. function checkIfDataReady() {
  229. if (customButtonsObj.length > 0) {
  230. appendCustomButtons(customButtonsObj);
  231. }
  232. else {
  233. setTimeout(checkIfDataReady, 300);
  234. }
  235. }
  236.  
  237. function hideButtons() {
  238. hideList.forEach((o) => {
  239. var button = document.querySelector(`#${o.bId}`);
  240.  
  241. if (button) {
  242. if (o.h === 'show') {
  243. button.style.display = '';
  244. }
  245. else if (o.h === 'hide') {
  246. button.style.display = 'none';
  247. }
  248. }
  249. });
  250. }
  251.  
  252. function makeButtonId(buttonName) {
  253. var result = 0;
  254. for (var i = 0; i < buttonName.length; i++) {
  255. result += buttonName.charCodeAt(i);
  256. }
  257.  
  258. result *= buttonName.charCodeAt(buttonName.length - 1);
  259.  
  260. return result;
  261. }
  262.  
  263.  
  264. function editButtonHandler(e) {
  265. togglePopup(true);
  266. }
  267.  
  268. function getPopup() {
  269. return document.querySelector('.buttonPopup');
  270. }
  271.  
  272. function showEditButton() {
  273. var editButton = document.querySelector('.editButton');
  274. editButton.style.display = '';
  275. editButton.parentElement.style.paddingRight = '0px';
  276. }
  277.  
  278. function hideEditButton() {
  279. var editButton = document.querySelector('.editButton');
  280. editButton.style.display = 'none';
  281. editButton.parentElement.style.paddingRight = '16px';
  282. }
  283.  
  284. function addAndCancelButtonsHandler(e) {
  285. var targetEl = e.target;
  286.  
  287. if (targetEl.className === 'addButton') {
  288. var valuesListPromise = GM.listValues();
  289. valuesListPromise.then(addButtonLogic);
  290. }
  291. else if (targetEl.className === 'cancelButton') {
  292. togglePopup(false);
  293. }
  294. else if (targetEl.className === 'deleteButton') {
  295. GM.deleteValue(document.querySelector('.titleInput').value)
  296. togglePopup(false);
  297. }
  298.  
  299.  
  300. }
  301.  
  302. function addAndEditTabButtonsHandler(e) {
  303. var target = e.target;
  304.  
  305. if (target.className.includes('Text')) {
  306. target = e.target.parentElement;
  307. }
  308.  
  309. if (target.className === 'addTab' && target.style.color === 'white') {
  310. var editTab = target.parentElement.children[1];
  311. hideTabSection(editTab, target);
  312. }
  313. else if (target.className === 'editTab' && target.style.color === 'white') {
  314. var addTab = target.parentElement.firstElementChild;
  315. hideTabSection(addTab, target);
  316. }
  317. }
  318.  
  319. function hideTabSection(toHide, toShow) {
  320. toHide.style.color = 'white';
  321. toHide.style.backgroundColor = '#d8d8d8';
  322. toShow.style.color = 'black';
  323. toShow.style.backgroundColor = 'white';
  324.  
  325. var sectionToHide;
  326. var sectionToShow;
  327.  
  328. if (toHide.className === 'addTab') {
  329. sectionToHide = document.querySelector('.addSection');
  330. sectionToShow = document.querySelector('.editSection');
  331. }
  332. else {
  333. sectionToHide = document.querySelector('.editSection');
  334. sectionToShow = document.querySelector('.addSection');
  335. }
  336.  
  337. sectionToHide.style.display = 'none';
  338. sectionToHide.style.height = '0%';
  339. sectionToHide.style.width = '0%';
  340. sectionToShow.style.display = 'block';
  341. sectionToShow.style.height = '100%';
  342. sectionToShow.style.width = '100%';
  343. }
  344.  
  345. function togglePopup(v) {
  346. var popUp = getPopup();
  347.  
  348. if (v) {
  349. popUp.style.opacity = '1';
  350. popUp.style.top = '50%';
  351. }
  352. else {
  353. popUp.style.opacity = '0';
  354. popUp.style.top = '-100%';
  355. }
  356. }
  357.  
  358. function addButtonLogic(valuesList) {
  359. var titleField = document.querySelector('.titleInput');
  360. var searchField = document.querySelector('.URLInput');
  361. var iconField = document.querySelector('.iconInput');
  362.  
  363. if (titleField.value === '') {
  364. toggleMsgBox(true, 'Title cannot be empty!', false);
  365. }
  366. else if (searchField.value === '') {
  367. toggleMsgBox(true, 'Search URL cannot be empty!', false);
  368. }
  369. else if (valuesList.includes(titleField.value)) {
  370. toggleMsgBox(true, 'Button with the same name already exists!', false);
  371. }
  372. else {
  373. if (iconField.value === '') {
  374. var regex = /(?:https?:\/\/)(w{0,3}\.?\w+\.\w+)\//;
  375.  
  376. if (regex.test(searchField.value)) {
  377. iconField.value = `https://www.google.com/s2/favicons?domain=${searchField.value.match(regex)[1]}`;
  378. }
  379. }
  380.  
  381. GM.setValue(titleField.value, JSON.stringify({
  382. title: titleField.value,
  383. url: searchField.value,
  384. icon: iconField.value
  385. }));
  386.  
  387. titleField.value = '';
  388. searchField.value = '';
  389. iconField.value = '';
  390.  
  391. /*
  392. var animeButtonsList = document.querySelector('.buttonsList');
  393. createAndAppendEditListEntry(animeButtonsList, [button], 6);
  394. header.insertBefore(button, editButton);
  395. */
  396.  
  397. toggleMsgBox(true, `Button ${titleField.value} added succsessfully! Reload to see it!`, true);
  398.  
  399. var button = creteButton(iconField.value, searchField.value, titleField.value);
  400. hideList.push({ bId: button.id, h: 'show' });
  401. GM.setValue('hideList', JSON.stringify(hideList));
  402. }
  403. }
  404.  
  405. function toggleMsgBox(toggle, msg, showReload) {
  406. var msgBox = document.querySelector('.addMsgBox');
  407.  
  408. if (msg) {
  409. msgBox.firstElementChild.textContent = msg;
  410. }
  411.  
  412. if (showReload) {
  413. msgBox.children[1].style.display = 'inline';
  414. }
  415. else {
  416. msgBox.children[1].style.display = 'none';
  417. }
  418.  
  419. if (toggle) {
  420. msgBox.style.opacity = '1';
  421. msgBox.style.bottom = '15%';
  422. }
  423. else {
  424. msgBox.style.opacity = '0';
  425. setTimeout(() => { msgBox.style.bottom = '150%'; }, 250);
  426. }
  427. }
  428.  
  429. function hideAndDeleteHandler(e) {
  430. var target = e.target;
  431. var buttPrent = target.parentElement;
  432. var button = document.querySelector(`#${buttPrent.className}`);
  433.  
  434. if (target.className === "removeButton") {
  435. button.remove();
  436. target.parentElement.remove();
  437. GM.deleteValue(buttPrent.textContent);
  438. hideList = hideList.filter(obj => obj.bId !== button.id);
  439.  
  440. GM.setValue('hideList', JSON.stringify(hideList));
  441. }
  442. else if (target.className === 'hideButton') {
  443. if (button.style.display === 'none') {
  444. button.style.display = '';
  445. concatHideList([{ bId: button.id, h: 'show' }]);
  446. target.setAttribute('src', iconEye);
  447. }
  448. else {
  449. button.style.display = 'none';
  450. concatHideList([{ bId: button.id, h: 'hide' }]);
  451. target.setAttribute('src', iconEyeGray);
  452. }
  453.  
  454. GM.setValue('hideList', JSON.stringify(hideList));
  455.  
  456. hideButtons();
  457. }
  458. }
  459.  
  460. function msgButtonsHandler(e) {
  461. var target = e.target;
  462.  
  463. if (target.className === 'reloadButton') {
  464. location.reload();
  465. }
  466. else if (target.className === 'closeButton') {
  467. toggleMsgBox(false);
  468. }
  469. }
  470.  
  471. var iconEyeGray = 'https://previews.dropbox.com/p/thumb/AAuWCCOL6JyGmMweL1F-_5DiAS2zJYRa5Lir0SbwC5DvS_0nQEwjuJvONWL8a5aBxxvBhMbmATHXk6HOq_p16qq_FCjHezpZK-WG59CrRBfTl2mY7-e1lE-Ce2r1JEgpQFmo0LllAXnpcbeH7-68AxkfuMN4g6ChfpHCoaX7r9YH8MCQVu01ect1cCdqHDYlJBqgRWUrbTjwrlIlV9Y545Eldz5Xp948EIoHnNVeov_ybS2u-oGDZWwFtN5FLGCtJTyXK2sLylpQ8cvH7DVl0DAVcGO0YF6_RqIwbCpt-yCS58gfClH3lTEmPKunqrBwfNQe0SxXvyXTr-1GbCDiP_Lq/p.png?size=2048x1536&size_mode=3';
  472.  
  473. var iconEye = 'https://previews.dropbox.com/p/thumb/AAvAf0hVyAwc9SRprGbA731CezYJ5amifW_2ApUxlRa0i98WlQoS13M3EQNGLv9kNTHsle6RsiUTlNZPtimWZM1ccs4i0orerrn0SwuPcsaGnU0cKho2IWWE-mEAhhoh779w04r8yWqJrAZZcYiy1mLZINV6SKIRq797-RW0gsZXZ8tgvcWa_nIAF2cpttnklJ93I0h2FFtmlrdX7WCzUBo2eML71mGMfRebI4b9wYnfFNT_77xWPeA1RoOaFLkYBKWF3wIsfnSCVGjodq_yHC6xjJJ2mwSbiRxuTO0glpiiT0AGN3hUTD0th5IbY5EPF-R4H1zPJMnPScAKax9RlrW5/p.png?fv_content=true&size_mode=5';
  474.  
  475.  
  476. function addButtonPopup() {
  477. var style = 'margin:auto;text-align: center;display:block;margin-bottom: 5px;';
  478. var popUp = createHTMLElement('div', null, 'buttonPopup', [{ n: 'style', v: 'position:absolute;top:-100%;left:50%;margin-top:-280px;margin-left:-200px;background-color:white;width:400px;height:560px;box-shadow: 0 0 15px rgba(0, 0, 0, 0.4);border-radius: 8px;font-size:medium;z-index:9999;opacity:0;transition: all 0.7s cubic-bezier(0.45, -0.24, 0.43, 1.14) 0s;' }]);
  479.  
  480. var tabs = createHTMLElement('div', null, 'popupTabs', [{ n: 'style', v: 'width: 100%;height: 40px;' }]);
  481. var addTab = createHTMLElement('div', null, 'addTab', [{ n: 'style', v: 'height: 100%;width: 50%;background-color: white;left: 50%;border-top-left-radius: 8px;text-align: center;transition: all 0.2s linear 0s;' }]);
  482. var textTabsStyle = 'position: relative;top: 11px;font-weight: bold;';
  483. var addTabText = createHTMLElement('div', 'ADD', 'addTabText', [{ n: 'style', v: textTabsStyle }]);
  484. addTab.appendChild(addTabText);
  485.  
  486. var editTab = createHTMLElement('div', null, 'editTab', [{ n: 'style', v: 'top: -40px;height: 100%;width: 50%;background-color: #d8d8d8;left: 50%;position: relative;border-top-right-radius: 8px;text-align: center;color: white;transition: all 0.2s linear 0s;' }]);
  487. var editTabText = createHTMLElement('div', 'EDIT', 'editTabText', [{ n: 'style', v: textTabsStyle }]);
  488. editTab.appendChild(editTabText);
  489.  
  490. appendChildren(tabs, [addTab, editTab]);
  491.  
  492. var addSection = createHTMLElement('div', null, 'addSection', [{ n: 'style', v: 'height:100%;width:100%;' }]);
  493. var addSectionTitle = createHTMLElement('h2', 'ADD CUSTOM BUTTON', null, [{ n: 'style', v: style + 'margin-top: 25px' }]);
  494. var title = createHTMLElement('h3', 'Title', null, [{ n: 'style', v: style + 'margin-top: 20px' }]);
  495. var titleInput = createHTMLElement('input', null, 'titleInput', [{ n: 'placeholder', v: 'Button title' }, { n: 'style', v: style }]);
  496. var URLTitle = createHTMLElement('h3', 'Search URL', null, [{ n: 'style', v: style + 'margin-top: 20px' }]);
  497. var URLDescr = createHTMLElement('div', 'To get the search URL first go the site you want to add and search the term "ANIMENAME" in the search field. Then copy the full URL (including http://) in the field below. (exaple: https://myanimelist.net/search/all?q=ANIMENAME)', null, [{ n: 'style', v: style + 'margin-left: 15px;margin-right: 15px;font-size: 90%;font-family: monospace;' }]);
  498. var URLInput = createHTMLElement('input', null, 'URLInput', [{ n: 'placeholder', v: 'Search URL' }, { n: 'style', v: style + 'width:80%' }]);
  499. var iconTitle = createHTMLElement('h3', 'Icon URL', null, [{ n: 'style', v: style + 'margin-top: 20px' }]);
  500. var iconDescr = createHTMLElement('div', null, null, [{ n: 'style', v: style + 'margin-left: 15px;margin-right: 15px;font-size: 90%;font-family: monospace;' }]);
  501. iconDescr.innerHTML = '(<b>Leave empty for automatic icon parse</b>)<br />Link to icon for the button. <br />The easiest way to get it is to copy this link "https://www.google.com/s2/favicons?domain=" and place the website url at the end (example: https://www.google.com/s2/favicons?domain=myanimelist.net).';
  502. var iconInput = createHTMLElement('input', null, 'iconInput', [{ n: 'placeholder', v: 'Icon URL' }, { n: 'style', v: style + 'width:80%' }]);
  503.  
  504. var msgBoxDiv = createHTMLElement('div', null, 'addMsgBox', [{ n: 'style', v: 'width: 86%;position: absolute;margin-left: 7%;bottom: 150%;background-color: white;border-radius: 8px;box-shadow: rgba(0,0,0, 0.4) 0px 0px 15px;text-align: center;transition: opacity 0.2s linear;opacity:0' }]);
  505. var msgText = createHTMLElement('div', 'Button added succsessfully! Reload to see it!', 'addMgsText', [{ n: 'style', v: 'margin: 10px;' }]);
  506. var reloadButton = createHTMLElement('button', 'RELOAD', 'reloadButton', [{ n: 'style', v: 'margin: 10px;margin-right:0px;width:90px;' }]);
  507. var closeButton = createHTMLElement('button', 'CLOSE', 'closeButton', [{ n: 'style', v: 'margin: 10px;width:90px;' }]);
  508. appendChildren(msgBoxDiv, [msgText, reloadButton, closeButton]);
  509.  
  510. var buttonsDiv = createHTMLElement('div', null, 'addAndCancelButtons', [{ n: 'style', v: style + 'bottom:10px;position:absolute;width:100%' }]);
  511. var addButton = createHTMLElement('button', 'ADD', 'addButton', [{ n: 'style', v: 'width:90px;margin:5px' }]);
  512. var cancelButton = createHTMLElement('button', 'CANCEL', 'cancelButton', [{ n: 'style', v: 'width:90px;margin:5px' }]);
  513.  
  514. var editSection = createHTMLElement('div', null, 'editSection', [{ n: 'style', v: 'height:0%;width:0%;display:none' }]);
  515. var editSectionTitle = createHTMLElement('h2', 'EDIT CUSTOM BUTTONS', null, [{ n: 'style', v: style + 'margin-top: 25px' }]);
  516. var animeButtonsList = createHTMLElement('ul', null, 'buttonsList', [{ n: 'style', v: 'list-style: none;margin-top: 25px;padding-left: 40px;' }]);
  517. var animeButtons = document.querySelectorAll('.animeButton');
  518. var editButtonsDiv = createHTMLElement('div', null, 'addAndCancelButtons', [{ n: 'style', v: style + 'bottom:10px;position:absolute;width:100%' }]);
  519. var cancelButtonEdit = createHTMLElement('button', 'CLOSE', 'cancelButton', [{ n: 'style', v: 'width:90px;margin:5px' }]);
  520. editButtonsDiv.appendChild(cancelButtonEdit);
  521.  
  522. createAndAppendEditListEntry(animeButtonsList, animeButtons, 1);
  523.  
  524. popUp.appendChild(tabs);
  525. appendChildren(buttonsDiv, [addButton, cancelButton]);
  526. appendChildren(addSection, [addSectionTitle, title, titleInput, URLTitle, URLDescr, URLInput, iconTitle, iconDescr, iconInput, msgBoxDiv, buttonsDiv]);
  527.  
  528. appendChildren(editSection, [editSectionTitle, animeButtonsList, editButtonsDiv]);
  529.  
  530. appendChildren(popUp, [addSection, editSection]);
  531. var html = document.querySelector('html');
  532. html.appendChild(popUp);
  533.  
  534. buttonsDiv.addEventListener('click', addAndCancelButtonsHandler);
  535. editButtonsDiv.addEventListener('click', addAndCancelButtonsHandler);
  536. tabs.addEventListener('click', addAndEditTabButtonsHandler);
  537. animeButtonsList.addEventListener('click', hideAndDeleteHandler);
  538. msgBoxDiv.addEventListener('click', msgButtonsHandler);
  539. }
  540.  
  541. function createAndAppendEditListEntry(animeButtonsList, animeButtons, counterStartVal) {
  542. var counter = counterStartVal;
  543.  
  544. animeButtons.forEach((b) => {
  545. var listEl = createHTMLElement('li', null, b.id, [{ n: 'style', v: 'width:90%;margin-top:5px;border-bottom-style: inset;border-bottom-width: thin;' }]);
  546. var imgUrl = b.firstElementChild.getAttribute('src');
  547. var img = createHTMLElement('img', null, null, [{ n: 'src', v: imgUrl }, { n: 'style', v: 'width: 16px;height: 16px;' }]);
  548. var span = createHTMLElement('span', b.getAttribute('title'), null, [{ n: 'style', v: 'margin-left:5px;bottom: 2px;position: relative;' }]);
  549. var hideIcon = createHTMLElement('img', null, 'hideButton', [{ n: 'src', v: iconEye }, { n: 'title', v: 'Toggle Hide' }, { n: 'style', v: 'height:16px;width:16px;position: absolute;right: 65px;' }]);
  550. var removeIcon = createHTMLElement('img', null, 'removeButton', [{ n: 'src', v: 'https://previews.dropbox.com/p/thumb/AAv_J1gX163dhysBBA0GBSGRBMMdRoTT2EVqs_xTg5PdES0EF5geKh9gJg0kCbmtTGSzjkZFZQ6qCVpKFmUKobTWUTYu-t6yYVdWg_ldZE8GBUfXu0NWx3q0RfyeelWLgApIOskJParENLlfHXLyKT_FeTPtESh3rNqWCr-7iY1v_snaIZo5WsajqOSeUoJ3jS6M0_lD_PN410Xv-hUbqlNejWUNJDoWz9nkQdhzLX3bFpErrb75jnys7fwG8NV0YYL-HDOKCOFnh0MCviaq_r-YeioUpcwdxVXv9AnHdgsfGnTSmfVdgY6oG5nk0IOjDfYs_R9-3zcOz5pClF6-9uM6/p.png?fv_content=true&size_mode=5' }, { n: 'title', v: 'DELETE' }, { n: 'style', v: 'height:16px;width:16px;position: absolute;right: 37px;' }]);
  551.  
  552. if (b.style.display === 'none') {
  553. hideIcon.setAttribute('src', iconEyeGray);
  554. }
  555.  
  556. appendChildren(listEl, [img, span, hideIcon]);
  557.  
  558. if (counter++ > 5) {
  559. listEl.appendChild(removeIcon);
  560. }
  561. animeButtonsList.appendChild(listEl);
  562. });
  563. }
  564.  
  565. function createHTMLElement(tag, textContent, className, attributes) {
  566. var element = document.createElement(tag);
  567.  
  568. if (className) {
  569. element.className = className;
  570. }
  571. if (textContent) {
  572. element.textContent = textContent;
  573. }
  574. if (attributes) {
  575. attributes.forEach((a) => {
  576. element.setAttribute(a.n, a.v);
  577. })
  578. }
  579.  
  580. return element;
  581. }
  582.  
  583. function appendChildren(element, children) {
  584. children.forEach((c) => {
  585. element.appendChild(c);
  586. })
  587. }
  588.  
  589. }