Anime Website Buttons Plus

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

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

  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.02
  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${buttonCounter++}` },
  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. function getHideList() {
  197. var promise = GM.getValue('hideList', '[]');
  198. promise.then((v) => {
  199. var localVal = JSON.parse(v);
  200. concatHideList(localVal);
  201. hideButtons();
  202. addButtonPopup();
  203. });
  204. }
  205.  
  206. function concatHideList(v) {
  207. v.forEach(b => {
  208. var item = hideList.find(n => n.bId === b.bId);
  209. if (item) { return Object.assign(item, b); }
  210. hideList.push(b);
  211. });
  212. }
  213.  
  214.  
  215. function getCustomButtons(values) {
  216. values.forEach(async (n) => {
  217. if (n !== 'hideList') {
  218. customButtonsObj.push(JSON.parse(await GM.getValue(n)));
  219. }
  220. });
  221.  
  222. checkIfDataReady();
  223. }
  224.  
  225. function checkIfDataReady() {
  226. if (customButtonsObj.length > 0) {
  227. appendCustomButtons(customButtonsObj);
  228. }
  229. else {
  230. setTimeout(checkIfDataReady, 300);
  231. }
  232. }
  233.  
  234. function hideButtons() {
  235. hideList.forEach((o) => {
  236. var button = document.querySelector(`#${o.bId}`);
  237.  
  238. if (button) {
  239. if (o.h === 'show') {
  240. button.style.display = '';
  241. }
  242. else if (o.h === 'hide') {
  243. button.style.display = 'none';
  244. }
  245. }
  246. });
  247. }
  248.  
  249.  
  250. function editButtonHandler(e) {
  251. togglePopup(true);
  252. }
  253.  
  254. function getPopup() {
  255. return document.querySelector('.buttonPopup');
  256. }
  257.  
  258. function showEditButton() {
  259. var editButton = document.querySelector('.editButton');
  260. editButton.style.display = '';
  261. editButton.parentElement.style.paddingRight = '0px';
  262. }
  263.  
  264. function hideEditButton() {
  265. var editButton = document.querySelector('.editButton');
  266. editButton.style.display = 'none';
  267. editButton.parentElement.style.paddingRight = '16px';
  268. }
  269.  
  270. function addAndCancelButtonsHandler(e) {
  271. var targetEl = e.target;
  272.  
  273. if (targetEl.className === 'addButton') {
  274. var valuesListPromise = GM.listValues();
  275. valuesListPromise.then(addButtonLogic);
  276. }
  277. else if (targetEl.className === 'cancelButton') {
  278. togglePopup(false);
  279. }
  280. else if (targetEl.className === 'deleteButton') {
  281. GM.deleteValue(document.querySelector('.titleInput').value)
  282. togglePopup(false);
  283. }
  284.  
  285.  
  286. }
  287.  
  288. function addAndEditTabButtonsHandler(e) {
  289. var target = e.target;
  290.  
  291. if (target.className.includes('Text')) {
  292. target = e.target.parentElement;
  293. }
  294.  
  295. if (target.className === 'addTab' && target.style.color === 'white') {
  296. var editTab = target.parentElement.children[1];
  297. hideTabSection(editTab, target);
  298. }
  299. else if (target.className === 'editTab' && target.style.color === 'white') {
  300. var addTab = target.parentElement.firstElementChild;
  301. hideTabSection(addTab, target);
  302. }
  303. }
  304.  
  305. function hideTabSection(toHide, toShow) {
  306. toHide.style.color = 'white';
  307. toHide.style.backgroundColor = '#d8d8d8';
  308. toShow.style.color = 'black';
  309. toShow.style.backgroundColor = 'white';
  310.  
  311. var sectionToHide;
  312. var sectionToShow;
  313.  
  314. if (toHide.className === 'addTab') {
  315. sectionToHide = document.querySelector('.addSection');
  316. sectionToShow = document.querySelector('.editSection');
  317. }
  318. else {
  319. sectionToHide = document.querySelector('.editSection');
  320. sectionToShow = document.querySelector('.addSection');
  321. }
  322. sectionToHide.style.display = 'none';
  323. sectionToHide.style.height = '0%';
  324. sectionToHide.style.width = '0%';
  325. sectionToShow.style.display = 'block';
  326. sectionToShow.style.height = '100%';
  327. sectionToShow.style.width = '100%';
  328. }
  329.  
  330. function togglePopup(v) {
  331. var popUp = getPopup();
  332.  
  333. if (v) {
  334. popUp.style.opacity = '1';
  335. popUp.style.top = '50%';
  336. }
  337. else {
  338. popUp.style.opacity = '0';
  339. popUp.style.top = '-100%';
  340. }
  341. }
  342.  
  343. function addButtonLogic(valuesList) {
  344. var titleField = document.querySelector('.titleInput');
  345. var searchField = document.querySelector('.URLInput');
  346. var iconField = document.querySelector('.iconInput');
  347.  
  348. if (titleField.value === '') {
  349. toggleMsgBox(true, 'Title cannot be empty!', false);
  350. }
  351. else if (searchField.value === '') {
  352. toggleMsgBox(true, 'Search URL cannot be empty!', false);
  353. }
  354. else if (valuesList.includes(titleField.value)) {
  355. toggleMsgBox(true, 'Button with the same name already exists!', false);
  356. }
  357. else {
  358. if (iconField.value === '') {
  359. var regex = /(?:https?:\/\/)(w{0,3}\.?\w+\.\w+)\//;
  360.  
  361. if (regex.test(searchField.value)) {
  362. iconField.value = `https://www.google.com/s2/favicons?domain=${searchField.value.match(regex)[1]}`;
  363. }
  364. }
  365.  
  366. GM.setValue(titleField.value, JSON.stringify({
  367. title: titleField.value,
  368. url: searchField.value,
  369. icon: iconField.value
  370. }));
  371.  
  372. titleField.value = '';
  373. searchField.value = '';
  374. iconField.value = '';
  375.  
  376. /*
  377. var animeButtonsList = document.querySelector('.buttonsList');
  378. createAndAppendEditListEntry(animeButtonsList, [button], 6);
  379. header.insertBefore(button, editButton);
  380. */
  381.  
  382. toggleMsgBox(true, `Button ${titleField.value} added succsessfully! Reload to see it!`, true);
  383.  
  384. var button = creteButton(iconField.value, searchField.value, titleField.value);
  385. hideList.push({ bId: button.id, h: 'show' });
  386. GM.setValue('hideList', JSON.stringify(hideList));
  387. }
  388. }
  389.  
  390. function toggleMsgBox(toggle, msg, showReload) {
  391. var msgBox = document.querySelector('.addMsgBox');
  392.  
  393. if (msg) {
  394. msgBox.firstElementChild.textContent = msg;
  395. }
  396.  
  397. if (showReload) {
  398. msgBox.children[1].style.display = 'inline';
  399. }
  400. else {
  401. msgBox.children[1].style.display = 'none';
  402. }
  403.  
  404. if (toggle) {
  405. msgBox.style.opacity = '1';
  406. msgBox.style.bottom = '15%';
  407. }
  408. else {
  409. msgBox.style.opacity = '0';
  410. setTimeout(() => {msgBox.style.bottom = '150%';}, 250);
  411. }
  412. }
  413.  
  414. function hideAndDeleteHandler(e) {
  415. var target = e.target;
  416. var buttPrent = target.parentElement;
  417. var button = document.querySelector(`#${buttPrent.className}`);
  418.  
  419. if (target.className === "removeButton") {
  420. button.remove();
  421. target.parentElement.remove();
  422. GM.deleteValue(buttPrent.textContent);
  423. hideList = hideList.filter(obj => obj.bId !== button.id);
  424.  
  425. GM.setValue('hideList', JSON.stringify(hideList));
  426. }
  427. else if (target.className === 'hideButton') {
  428. if (button.style.display === 'none') {
  429. button.style.display = '';
  430. concatHideList([{ bId: button.id, h: 'show' }]);
  431. target.setAttribute('src', iconEye);
  432. }
  433. else {
  434. button.style.display = 'none';
  435. concatHideList([{ bId: button.id, h: 'hide' }]);
  436. target.setAttribute('src', iconEyeGray);
  437. }
  438.  
  439. GM.setValue('hideList', JSON.stringify(hideList));
  440.  
  441. hideButtons();
  442. }
  443. }
  444.  
  445. function msgButtonsHandler(e) {
  446. var target = e.target;
  447.  
  448. if (target.className === 'reloadButton') {
  449. location.reload();
  450. }
  451. else if (target.className === 'closeButton') {
  452. toggleMsgBox(false);
  453. }
  454. }
  455.  
  456. 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';
  457.  
  458. var iconEye = 'https://previews.dropbox.com/p/thumb/AAvAf0hVyAwc9SRprGbA731CezYJ5amifW_2ApUxlRa0i98WlQoS13M3EQNGLv9kNTHsle6RsiUTlNZPtimWZM1ccs4i0orerrn0SwuPcsaGnU0cKho2IWWE-mEAhhoh779w04r8yWqJrAZZcYiy1mLZINV6SKIRq797-RW0gsZXZ8tgvcWa_nIAF2cpttnklJ93I0h2FFtmlrdX7WCzUBo2eML71mGMfRebI4b9wYnfFNT_77xWPeA1RoOaFLkYBKWF3wIsfnSCVGjodq_yHC6xjJJ2mwSbiRxuTO0glpiiT0AGN3hUTD0th5IbY5EPF-R4H1zPJMnPScAKax9RlrW5/p.png?fv_content=true&size_mode=5';
  459.  
  460.  
  461. function addButtonPopup() {
  462. var style = 'margin:auto;text-align: center;display:block;margin-bottom: 5px;';
  463. 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;' }]);
  464.  
  465. var tabs = createHTMLElement('div', null, 'popupTabs', [{ n: 'style', v: 'width: 100%;height: 40px;' }]);
  466. 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;' }]);
  467. var textTabsStyle = 'position: relative;top: 11px;font-weight: bold;';
  468. var addTabText = createHTMLElement('div', 'ADD', 'addTabText', [{ n: 'style', v: textTabsStyle }]);
  469. addTab.appendChild(addTabText);
  470.  
  471. 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;' }]);
  472. var editTabText = createHTMLElement('div', 'EDIT', 'editTabText', [{ n: 'style', v: textTabsStyle }]);
  473. editTab.appendChild(editTabText);
  474.  
  475. appendChildren(tabs, [addTab, editTab]);
  476.  
  477. var addSection = createHTMLElement('div', null, 'addSection', [{ n: 'style', v: 'height:100%;width:100%;' }]);
  478. var addSectionTitle = createHTMLElement('h2', 'ADD CUSTOM BUTTON', null, [{ n: 'style', v: style + 'margin-top: 25px' }]);
  479. var title = createHTMLElement('h3', 'Title', null, [{ n: 'style', v: style + 'margin-top: 20px' }]);
  480. var titleInput = createHTMLElement('input', null, 'titleInput', [{ n: 'placeholder', v: 'Button title' }, { n: 'style', v: style }]);
  481. var URLTitle = createHTMLElement('h3', 'Search URL', null, [{ n: 'style', v: style + 'margin-top: 20px' }]);
  482. 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;' }]);
  483. var URLInput = createHTMLElement('input', null, 'URLInput', [{ n: 'placeholder', v: 'Search URL' }, { n: 'style', v: style + 'width:80%' }]);
  484. var iconTitle = createHTMLElement('h3', 'Icon URL', null, [{ n: 'style', v: style + 'margin-top: 20px' }]);
  485. var iconDescr = createHTMLElement('div', null, null, [{ n: 'style', v: style + 'margin-left: 15px;margin-right: 15px;font-size: 90%;font-family: monospace;' }]);
  486. 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).';
  487. var iconInput = createHTMLElement('input', null, 'iconInput', [{ n: 'placeholder', v: 'Icon URL' }, { n: 'style', v: style + 'width:80%' }]);
  488.  
  489. 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' }]);
  490. var msgText = createHTMLElement('div', 'Button added succsessfully! Reload to see it!', 'addMgsText', [{ n: 'style', v: 'margin: 10px;' }]);
  491. var reloadButton = createHTMLElement('button', 'RELOAD', 'reloadButton', [{ n: 'style', v: 'margin: 10px;margin-right:0px;width:90px;' }]);
  492. var closeButton = createHTMLElement('button', 'CLOSE', 'closeButton', [{ n: 'style', v: 'margin: 10px;width:90px;' }]);
  493. appendChildren(msgBoxDiv, [msgText, reloadButton, closeButton]);
  494.  
  495. var buttonsDiv = createHTMLElement('div', null, 'addAndCancelButtons', [{ n: 'style', v: style + 'bottom:10px;position:absolute;width:100%' }]);
  496. var addButton = createHTMLElement('button', 'ADD', 'addButton', [{ n: 'style', v: 'width:90px;margin:5px' }]);
  497. var cancelButton = createHTMLElement('button', 'CANCEL', 'cancelButton', [{ n: 'style', v: 'width:90px;margin:5px' }]);
  498.  
  499. var editSection = createHTMLElement('div', null, 'editSection', [{ n: 'style', v: 'height:0%;width:0%;display:none' }]);
  500. var editSectionTitle = createHTMLElement('h2', 'EDIT CUSTOM BUTTONS', null, [{ n: 'style', v: style + 'margin-top: 25px' }]);
  501. var animeButtonsList = createHTMLElement('ul', null, 'buttonsList', [{ n: 'style', v: 'list-style: none;margin-top: 25px;padding-left: 40px;' }]);
  502. var animeButtons = document.querySelectorAll('.animeButton');
  503. var editButtonsDiv = createHTMLElement('div', null, 'addAndCancelButtons', [{ n: 'style', v: style + 'bottom:10px;position:absolute;width:100%' }]);
  504. var cancelButtonEdit = createHTMLElement('button', 'CLOSE', 'cancelButton', [{ n: 'style', v: 'width:90px;margin:5px' }]);
  505. editButtonsDiv.appendChild(cancelButtonEdit);
  506.  
  507. createAndAppendEditListEntry(animeButtonsList, animeButtons, 1);
  508.  
  509. popUp.appendChild(tabs);
  510. appendChildren(buttonsDiv, [addButton, cancelButton]);
  511. appendChildren(addSection, [addSectionTitle, title, titleInput, URLTitle, URLDescr, URLInput, iconTitle, iconDescr, iconInput, msgBoxDiv, buttonsDiv]);
  512.  
  513. appendChildren(editSection, [editSectionTitle, animeButtonsList, editButtonsDiv]);
  514.  
  515. appendChildren(popUp, [addSection, editSection]);
  516. var html = document.querySelector('html');
  517. html.appendChild(popUp);
  518.  
  519. buttonsDiv.addEventListener('click', addAndCancelButtonsHandler);
  520. editButtonsDiv.addEventListener('click', addAndCancelButtonsHandler);
  521. tabs.addEventListener('click', addAndEditTabButtonsHandler);
  522. animeButtonsList.addEventListener('click', hideAndDeleteHandler);
  523. msgBoxDiv.addEventListener('click', msgButtonsHandler);
  524. }
  525.  
  526. function createAndAppendEditListEntry(animeButtonsList, animeButtons, counterStartVal) {
  527. var counter = counterStartVal;
  528.  
  529. animeButtons.forEach((b) => {
  530. var listEl = createHTMLElement('li', null, b.id, [{ n: 'style', v: 'width:90%;margin-top:5px;border-bottom-style: inset;border-bottom-width: thin;' }]);
  531. var imgUrl = b.firstElementChild.getAttribute('src');
  532. var img = createHTMLElement('img', null, null, [{ n: 'src', v: imgUrl }, { n: 'style', v: 'width: 16px;height: 16px;' }]);
  533. var span = createHTMLElement('span', b.getAttribute('title'), null, [{ n: 'style', v: 'margin-left:5px;bottom: 2px;position: relative;' }]);
  534. 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;' }]);
  535. 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;' }]);
  536.  
  537. if (b.style.display === 'none') {
  538. hideIcon.setAttribute('src', iconEyeGray);
  539. }
  540.  
  541. appendChildren(listEl, [img, span, hideIcon]);
  542.  
  543. if (counter++ > 5) {
  544. listEl.appendChild(removeIcon);
  545. }
  546. animeButtonsList.appendChild(listEl);
  547. });
  548. }
  549.  
  550. function createHTMLElement(tag, textContent, className, attributes) {
  551. var element = document.createElement(tag);
  552.  
  553. if (className) {
  554. element.className = className;
  555. }
  556. if (textContent) {
  557. element.textContent = textContent;
  558. }
  559. if (attributes) {
  560. attributes.forEach((a) => {
  561. element.setAttribute(a.n, a.v);
  562. })
  563. }
  564.  
  565. return element;
  566. }
  567.  
  568. function appendChildren(element, children) {
  569. children.forEach((c) => {
  570. element.appendChild(c);
  571. })
  572. }
  573.  
  574. }