Kawiesh

[OLD] Link Lister & Text Merger

Jan 6th, 2021 (edited)
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. let width= '140px'; //change if needed
  2. let b=[
  3. `title>>>url`,
  4. `title>>>url`,
  5. `title>>>url`,
  6. ];
  7.  
  8. let b1= [], b2= [];
  9. for (let i=0; i<b.length; i++) {
  10. if (b[i].includes('>>>')){
  11. let split = b[i].split('>>>');
  12. b1.push(split[0]);
  13. b2.push(split[1]);}}
  14.  
  15. let a= document.createElement('div');
  16.     a.id= 'bmlist';
  17.     document.body.appendChild(a);
  18.  
  19. let menu = document.createElement('span');
  20.     menu.innerHTML = '❌';
  21.     a.appendChild(menu);
  22.  
  23. function kd (x,y) {
  24. let link = document.createElement('a');
  25.     link.href= x;
  26.     link.textContent= y;
  27.     link.target= '_blank';
  28.     a.appendChild(link);}
  29.  
  30. for(let i=0; i<b1.length; i++){
  31. kd(b2[i],b1[i]);}
  32.  
  33. let c= document.querySelector('#bmlist');
  34.     c.style.top= '10px';
  35.     c.style.left= '10px';
  36.     c.style.width= width;
  37.     c.style.textAlign= 'left';
  38.     c.style.position= 'fixed';
  39.     c.style.zIndex= '10123456';
  40.     c.style.boxSizing= 'border-box';
  41.     c.style.visibility= 'visible';
  42.  
  43. let d= document.querySelector('#bmlist span');
  44.     d.style.textAlign= 'center';
  45.     d.style.border= '1px solid red';
  46.  
  47. let e= document.querySelectorAll('#bmlist a'); 
  48. for (let i=0; i<e.length; i++){
  49.     e[i].style.display= 'inline-block';
  50.     e[i].style.border= '1px solid fuchsia';
  51.     e[i].style.boxSizing= 'border-box';
  52.     e[i].style.padding= '4px 0 4px 10px';
  53.     e[i].style.background= 'black';
  54.     e[i].style.color= 'white';
  55.     e[i].style.width= '100%';
  56.     e[i].style.font= '14px arial';
  57.     e[i].style.textDecoration= 'none';}
  58.  
  59. d.onclick= function() {
  60. for(let i=0; i<e.length; i++){
  61. if (e[i].style.display==('none'))
  62. e[i].style.display= 'inline-block';
  63. else e[i].style.display= 'none'; }};
  64.  
  65.  
  66.  
  67. /*-----------------------------------------------------------------------------------------------------------*/
  68.  
  69. <!DOCTYPE html>
  70. <html lang="en">
  71. <head>
  72. <style>
  73. input{
  74. background:black;
  75. color: white;
  76. border: 1px solid green;
  77. }
  78. </style>
  79. </head>
  80. <body>
  81. <div>          
  82. <span>Start</span>
  83. <form   id="begin" rows="1" cols="8">
  84. <textarea rows="1" cols="8"></textarea></form>
  85.  
  86. <span>Joiner</span>
  87. <form   id="middle">
  88. <textarea rows="1" cols="8"></textarea></form>
  89.  
  90. <span>End</span>
  91. <form id="end">
  92. <textarea rows="1" cols="8"></textarea></form>
  93. </div>
  94.  
  95. <br>
  96. <br>
  97.                
  98. <div    style="clear:both">
  99. <h3>List of Titles<h3>
  100. <form id="titles">
  101. <textarea rows="20" cols="70"></textarea>
  102. </form><br>
  103.  
  104. <h3>List Of URLs<h3>
  105. <form id="urls" onsubmit="KD();return false;">
  106.  <textarea rows="20" cols="70"></textarea>
  107.  <input type="submit">
  108. </form><br>
  109.  
  110. <h3>Result<h3>
  111. <form id="result">
  112.  <textarea rows="30" cols="70" readonly></textarea>
  113. </form>
  114. </div>
  115.  
  116. <script>
  117. let a= document.querySelector('#titles textarea'),     
  118.     b= document.querySelector('#urls textarea'),
  119.     c= document.querySelector('#result textarea'),
  120.     d= document.querySelector('#begin textarea'),
  121.     e= document.querySelector('#middle textarea'),
  122.     f= document.querySelector('#end textarea');
  123.  
  124. //---------PLACEHOLDER--CONFIGURATION-------
  125. let aPH=`Paste a list of your Titles here,
  126. separated by linebreaks. Example:
  127. Title 1
  128. Title 2
  129. Title 3`; //@@@@@@@@@@@@@@@@@@@
  130.  
  131. a.placeholder= aPH;
  132. a.onfocus= function() {a.placeholder='';}
  133. a.onblur= function() {a.placeholder=aPH;};
  134.  
  135. let bPH=`Paste a list of your URLs here,
  136. separated by linebreaks. Example:
  137. URL 1
  138. URL 2
  139. URL 3`; //@@@@@@@@@@@@@@@@@@@
  140.  
  141. b.placeholder=bPH;
  142. b.onfocus= function() {b.placeholder='';}
  143. b.onblur= function() {b.placeholder=bPH;}
  144.  
  145. //----------------ERROR--ALERTING------------------
  146. let er1= '*ERROR*',
  147. er2= `There were some potential errors in your input:
  148. - The Tite/URL list is empty
  149. - The Title/URL list contains extra linebreak(s)
  150. - The amount of Titles > the amount of URLs`,
  151. er3= `Oops! Your input contains backticks \`
  152. This can cause problems, and
  153. has therefore been escaped by \\\``;
  154.  
  155.  
  156. //-----------------MAIN--FUNCTION-----------------
  157. let bt= false;
  158.  
  159. function kd(x,y,z) {
  160. c.textContent='';
  161. let a1= a.value.split('\n'),
  162.     b1= b.value.split('\n'),
  163.     merged= [];
  164.    
  165. for (let i=0; i<a1.length; i++) {
  166.   if (a1[i]=='') a1[i]=er1;
  167.   if (b1[i]=='') b1[i]=er1;
  168.   if (b1[i]==0) b1[i]=er1;
  169.   if (b1[i]==undefined) b1[i]=er1;
  170.   if (a1[i].includes('`')){ bt= true;
  171.   a1[i]=a1[i].replace(/`/g,'\\`');}
  172.   if (b1[i].includes('`')){ bt= true;
  173.   b1[i]=b1[i].replace(/`/g,'\`');}
  174.  
  175. merged.push(`${x+a1[i]+y+b1[i]+z}`);
  176.  
  177. let result = document.createTextNode(merged[i]+'\n');
  178. c.appendChild(result);
  179. }
  180. }
  181.  
  182. //----------FUNCTION--W/--PARAMETER----------------
  183. d.value='`';
  184. e.value='>>>';
  185. f.value='`,'; //@@@@@@@@@@@@@@@@@@@
  186.  
  187. function KD() {
  188. let X=d.value, Y=e.value, Z=f.value;
  189. kd(X,Y,Z);
  190. if (bt==true) alert(er3);
  191. if (c.textContent.includes(er1)) alert (er2);
  192. }
  193. </script>
  194. </body>
  195. </html>
Add Comment
Please, Sign In to add comment