Advertisement
asmodeus94

link sorter

Aug 29th, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 1.63 KB | None | 0 0
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <style type="text/css">
  6. #main, #result{
  7.         margin:0 auto;
  8.         width:800px;
  9. }
  10. #result{
  11.         margin-top: 20px;
  12. }
  13. #buttons{
  14.         width:800px;
  15.         margin:0 auto;
  16.         text-align:center;
  17. }
  18. </style>
  19. <title>Sortowanie po partach</title>
  20. </head>
  21. <body>
  22. <div id="main">
  23.         <textarea id="txt" style="width:800px;height:200px;" placeholder="Podaj linki w tym miejscu"></textarea>
  24. </div>
  25. <div id="result">
  26.         <textarea id="txtR" style="width:800px;height:200px;" placeholder="Tu pojawi się wynik"></textarea>
  27.         <div id="buttons">
  28.             <input id="sort" type="button" value="Sortuj po partach"/>
  29.         </div>
  30. </div>
  31. <script type="text/javascript">
  32. var d = document;
  33.  
  34. function regx (ab) {
  35.     abT = ab.match(/\.part([\d]+)\./);
  36.     return abT != undefined ? abT[1] : ab;
  37. }
  38.  
  39. d.getElementById("sort").onclick = function() {
  40.     var urls = d.getElementById("txt");
  41.     urls = urls.value.split('\n');
  42.     var newUrls = [];
  43.     for (key in urls) {
  44.         if (urls[key] != '') {
  45.             newUrls.push(urls[key]);
  46.         }
  47.     }
  48.    
  49.     newUrls.sort(function(a, b) {
  50.         a = regx(a);
  51.         b = regx(b);
  52.         return (a > b) - (a < b);
  53.     });
  54.     var sortedUrls = d.getElementById("txtR");
  55.     sortedUrls.value = '';
  56.     for (var i = 0; i < newUrls.length; i++) {
  57.         sortedUrls.value += newUrls[i];
  58.         if (i < newUrls.length - 1) {
  59.             sortedUrls.value += '\n';
  60.         }
  61.     }
  62. }
  63. </script>
  64. </body>
  65. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement