Dump shit

I'm sick of right clicking download or resorting to the shitty 1 click downloader (which doesn't use the timestamp filename) for my cartoons

  1. // ==UserScript==
  2. // @name Dump shit
  3. // @version 1.1
  4. // @description I'm sick of right clicking download or resorting to the shitty 1 click downloader (which doesn't use the timestamp filename) for my cartoons
  5. // @author Ayoholup
  6. // @match *://*/*
  7. // @grant GM_download
  8. // @require https://code.jquery.com/jquery-3.1.1.min.js
  9. // @namespace https://greasyfork.org/users/476679
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. const HOTKEY = "NumpadMultiply";
  14.  
  15. let previews4Chan = (src) => {
  16. let spl = src.split(".");
  17. let filename = spl[spl.length - 2];
  18. let hasS = filename.substr(filename.length - 1).toLowerCase() == "s";
  19. if (hasS) { spl[spl.length-2] = spl[spl.length-2].slice(0, -1); }
  20. return spl.join(".");
  21. };
  22. //forceExt is to bruce force all extensions in the array below.
  23. //not needed for tiktok as videos only have 1 extension and is provided before calling the download function.
  24. let download = (url, filename, forceExt = false) => {
  25. if (!forceExt) {
  26. //runs if you know the specific file extension needed.
  27. GM_download({
  28. url: url,
  29. name: filename,
  30. onload: () => console.log(`${filename} worked out fine`)
  31. });
  32. } else {
  33. //brute forces all the following file extensions. Only 1 will work so no duplicates i hope
  34. let ext = ["jpg", "jpeg", "png", "gif", "webm", "mp4"].forEach((ext) => {
  35. let newURL = url.substring(0, url.lastIndexOf(".") + 1) + ext;
  36. let newFilename = filename.substring(0, filename.lastIndexOf(".") + 1) + ext;
  37. GM_download({
  38. url: newURL,
  39. name: newFilename,
  40. onload: () => console.log(`${newFilename} worked out fine`),
  41. onerror: (error, details) => console.log(error, details)
  42. });
  43. });
  44. }
  45. }
  46. let parseImg = (e) => {
  47. if (e.code == HOTKEY) {
  48. let hover = Array.from(document.querySelectorAll(":hover"));
  49. hover.forEach((el) => {
  50. //images and stuff (4chan etc...)
  51. if (el.tagName.toLowerCase() == "img") {
  52. let src = el.currentSrc;
  53. //Downloads full image if hovering over preview
  54. if (window.location.hostname.includes("4chan")) {
  55. src = previews4Chan(src);
  56. }
  57. //filename without extension, will be brute forced later.
  58. let filename = src.split("/").pop();
  59. console.log(`Downloading URL: ${src} into Filename: ${filename}`);
  60. download(src, filename, forceURLExt = true);
  61. }
  62. });
  63. }
  64. };
  65. document.addEventListener("keydown", parseImg);
  66. })();