Advertisement
SerDIDG

Parser / urait.ru

May 26th, 2020 (edited)
991
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (() => {
  2. const ID = window.content_id;
  3. const PAGES_URL = 'https://urait.ru/viewer/getData/' + ID;
  4. const PAGE_URL = 'https://urait.ru/viewer/getPage/' + ID + '/$1';
  5. const HEADERS = {
  6.     'X-Requested-With': 'XMLHttpRequest'
  7. };
  8.  
  9. /*** COMMON ***/
  10.  
  11. function addCSS(css) {
  12.     let styleElem = document.createElement( 'style' );
  13.     styleElem.appendChild( document.createTextNode( css ) );
  14.     document.getElementsByTagName( 'head' )[0].appendChild( styleElem );
  15. }
  16.  
  17. /*** REQUEST ***/
  18.  
  19. async function request() {
  20.     const response = await requestPages();
  21.     return await processPages(response);
  22. }
  23.  
  24. async function requestPages(){
  25.     const request = await fetch(PAGES_URL, {
  26.         'method' : 'POST',
  27.         'headers' : HEADERS
  28.     });
  29.     return await request.json();
  30. }
  31.  
  32. async function processPages(response) {
  33.     const links = [];
  34.     for (let i = 1; i <= response.pages.count; i++){
  35.         let link = PAGE_URL.replace('$1', i);
  36.         links.push(link);
  37.     }
  38.     return links;
  39. }
  40.  
  41. /*** RENDER ***/
  42.  
  43. function render(links) {
  44.     addCSS('\
  45.       .hack_container { position:fixed; top:0; right:0; bottom:0; left: 0; padding:24px; overflow:auto; z-index:9999; background:white; }\
  46.       .hack_container textarea { width:100%; height:100%; resize:none; }\
  47.       .hack_container_close { position:absolute; top:4px; right: 24px; z-index:2; }\
  48.   ');
  49.  
  50.     const container = document.createElement('div');
  51.     container.classList.add('hack_container');
  52.  
  53.     const close = document.createElement('div');
  54.     close.innerText = 'Закрыть';
  55.     close.classList.add('hack_container_close');
  56.     close.addEventListener('click', function(){
  57.         document.body.removeChild(container);
  58.     });
  59.     container.appendChild(close);
  60.  
  61.     const textarea = document.createElement('textarea');
  62.     textarea.value = links.join('\n');
  63.     container.appendChild(textarea);
  64.  
  65.     document.body.appendChild(container);
  66. }
  67.  
  68. /*** BOOTSTRAP ***/
  69.  
  70. request().then(render);
  71.  
  72. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement