Advertisement
Guest User

Untitled

a guest
Mar 6th, 2023
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. xhtmlrequest:
  2.  
  3. function save(blob, fileName) {
  4.     const link = document.createElement('a');
  5.     link.href = blob;
  6.     link.download = fileName;
  7.     link.dispatchEvent(new MouseEvent('click'));
  8.     window.setTimeout(() => window.URL.revokeObjectURL(blob), 1000);
  9. }
  10. function download({ url, name }) {
  11. let req = new XMLHttpRequest();
  12. req.open( "GET", url, true );
  13. req.setRequestHeader("origin", url);
  14.     req.responseType = "blob";
  15. req.send (null);
  16. req.onload = function(resp){
  17.     var img = document.createElement('img');
  18.     img.src = window.URL.createObjectURL(req.response);
  19.     document.body.appendChild(img);
  20.   save(img.src,name)
  21.         }
  22. }
  23. document.addEventListener('contextmenu', event => {
  24. const img = event.currentTarget.querySelector('a') || {};
  25.     const src = event.target.href;
  26. if (src.toString().includes(".js")||src.toString().includes(".css")||src.toString().includes(".txt")||src.toString().includes(".json")||src.toString().includes(".mp4")){
  27.     const filename = document.title;
  28.     download({ url: src, name: filename });
  29. }
  30. });
  31.  
  32.  
  33.  
  34. fetch request :
  35.  
  36.  
  37. function save(blob, fileName) {
  38.     const link = document.createElement('a');
  39.     link.href = blob;
  40.     link.download = fileName;
  41.     link.dispatchEvent(new MouseEvent('click'));
  42.     window.setTimeout(() => window.URL.revokeObjectURL(blob), 1000);
  43. }
  44. function download({ url, name }) {
  45. fetch(url).then(function(resp){
  46.     var img = document.createElement('img');
  47.     img.src = response.json();
  48.     document.body.appendChild(img);
  49.   save(img.src,name)
  50. })}
  51. document.addEventListener('contextmenu', event => {
  52. const img = event.currentTarget.querySelector('a') || {};
  53.     const src = event.target.href;
  54. if (src.toString().includes(".js")||src.toString().includes(".css")||src.toString().includes(".txt")||src.toString().includes(".json")||src.toString().includes(".mp4")){
  55.     const filename = document.title;
  56.     download({ url: src, name: filename });
  57. }
  58. });
  59.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement