SHARE
TWEET

Untitled

a guest Sep 22nd, 2019 89 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name        TS4 gallery downloader
  3. // @author      anadius
  4. // @match       *://www.ea.com/*/games/the-sims/the-sims-4/pc/gallery*
  5. // @match       *://www.ea.com/games/the-sims/the-sims-4/pc/gallery*
  6. // @version     1.0
  7. // @grant       unsafeWindow
  8. // @namespace   anadius.github.io
  9. // @icon        https://anadius.github.io/ts4installer-tumblr-files/userjs/favicon.png
  10. // ==/UserScript==
  11.  
  12. const realDownload = async (uuid, debug) => {
  13.   const result = await fetch('https://anadius.heliohost.org/ts4gallery/download.php?id=' + encodeURIComponent(uuid), {mode: "cors"});
  14.   const data = await result.json();
  15.   if(debug === true) {
  16.     console.log(uuid, data);
  17.   }
  18.   else {
  19.     if(data.success)
  20.       window.open('https://simfileshare.net' + data.url, '_blank');
  21.     else
  22.       alert(data.message);
  23.   }
  24. };
  25.  
  26. const toggleDownload = (scope, downloading) => {
  27.   scope.vm.toggleDownload.toggling = downloading;
  28.   scope.$apply();
  29. };
  30.  
  31. const download = async element => {
  32.   const scope = unsafeWindow.angular.element(element).scope();
  33.   toggleDownload(scope, true);
  34.   await realDownload(scope.vm.uuid, unsafeWindow.debug);
  35.   toggleDownload(scope, false);
  36. };
  37.  
  38. document.addEventListener('click', e => {
  39.   let el = e.target;
  40.   if(el.tagName === 'SPAN')
  41.     el = el.parentNode.parentNode;
  42.   else if(el.tagName === 'A')
  43.     el = el.parentNode;
  44.  
  45.   if(el.tagName === 'LI' && el.classList.contains('stream-tile__actions-download')) {
  46.     e.stopPropagation();
  47.     download(el);
  48.   }
  49. }, true);
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top