pixelmatorTutorialDownloader

download pixcelmator pro tutorial resouces and youtube videos to local disk

当前为 2023-03-28 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name pixelmatorTutorialDownloader
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.05
  5. // @description download pixcelmator pro tutorial resouces and youtube videos to local disk
  6. // @author mooring@codernote.club
  7. // @match https://www.pixelmator.com/tutorials/*
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=pixelmator.com
  9. // @run-at document-end
  10. // @grant GM_registerMenuCommand
  11. // @license MIT
  12. // ==/UserScript==
  13.  
  14. let proxy = '';
  15.  
  16. function getCategoryInfo(cmd, collect, init){
  17. let category = document.querySelector('.tutorialsBrowser__categoriesList >.tutorialsBrowser__categoriesItem.is-active').innerText;
  18. let moreless = document.querySelector('.tutorialsBrowser__mainCategoryMore>.tutorialsBrowser__mainCategoryMoreBtn');
  19. let commands = [];
  20. let download = [];
  21. let html = [];
  22. let foldmap = {};
  23. if(!moreless.parentElement.classList.contains('is-inactive')){
  24. moreless.click();
  25. }
  26. if(init){
  27. commands.push('cls');
  28. commands.push('@set pwd=%25~dp0');
  29. commands.push('@set getpage=%25~dp0\\..\\getpage.exe');
  30. commands.push(`@echo @set down=..\\yt-dlp --write-thumbnail --embed-metadata --cache-dir cache --write-link -f "bv[ext=mp4]+ba[ext=m4a]" --progress ${proxy?'--proxy "'+proxy+'"':''} --no-playlist --restrict-filenames --write-subs --audio-quality 10 --merge-output-format "mp4/mkv" --sub-langs "en-US.*,zh-Hans.*" --convert-thumbnails png --ffmpeg-location ..\\ ${init?'>':'>>'} %25~dp0\\${collect||category}_ytb.cmd`);
  31. html.push(`<!doctype html>`);
  32. html.push(`<html lang="en-US">`)
  33. html.push(`<head>`)
  34. html.push(`<meta charset="utf-8"/>`)
  35. html.push(`<title>Pixelmator Pro Tutorial</title>`)
  36. html.push(`<meta name="author" content="mooring@codernote.club"/>`)
  37. html.push(`<meta name="description" content="Pixelmator Pro Tutorial"/>`)
  38. html.push(`<meta name="viewport" content="width=device-width, initial-scale=1"/>`)
  39. html.push(`<style>`);
  40. html.push(`h2.category {width: 80%;display: block;border-bottom: 1px dodgerblue dotted;margin: 0.5em auto;padding-bottom: 0.5em;}`);
  41. html.push(`.items {width: 80%;margin: 0 auto;display: flex;flex-wrap: wrap;justify-content:flex-start}`);
  42. html.push(`.item {width:23.7em;padding:10px}`);
  43. html.push(`.img {width: 100%;height: 13em;cursor:pointer;position:relative;}`);
  44. html.push(`.img:before{display:block;width:3em;height:3em;content:"▶️";border-radius:2em;position:absolute;left:8.6em;top:3.8em;font-size:20px;color:white;text-align:center;line-height:3em;padding:0;margin:0;}`);
  45. html.push(`.title {font-weight:600;cursor:pointer;text-align: center;font-size: 1.2em;padding-bottom: 1em;}`);
  46. html.push(`img.image-x2 {width: 100%;height: 100%;border-radius: 1em;}`);
  47. html.push(`</style>`);
  48. html.push(`<script>`);
  49. html.push(`function viewVideo(evt,url){ var img=new Image(); img.onerror=function(){window.open(url.replace("video.mp4","index.html"))};img.onload=function(){window.open(url)};img.src=url.replace(".mp4",".png");}`);
  50. html.push(`</script></head><body>`);
  51. commands.push(`@echo @echo tutorial resource downloader ${init?'>':'>>'} %25~dp0\\${collect||category}_res.cmd`);
  52. }
  53. commands.push(`@if not exist ${category} mkdir ${category}`);
  54. commands.push(`@cd ${category}`);
  55. let items = document.querySelectorAll('.tutorialsBrowser__mainCategoryList >.tutorialsBrowser__mainItem');
  56. items.forEach((item,index)=>{
  57. let img = item.querySelector('.tutorialsThumbnail__image');
  58. let lnk = item.querySelector('.tutorialsThumbnail__link').href;
  59. let tit = item.querySelector('.tutorialsThumbnail__title').innerText;
  60. let src = 'https:'+img.getAttribute('src').replace(/^https?:/i,'');
  61. let x2 = 'https:'+img.getAttribute('srcset').replace(/^https?:/i,'');
  62. let pth = lnk.split('/').slice(-2,-1)[0];
  63. src = src.split('/');
  64. x2 = x2.split('/');
  65. if(!foldmap[pth]){
  66. foldmap[pth] = 1;
  67. commands.push(`@if not exist "${pth}\\img" mkdir "${pth}\\img"`);
  68. }
  69. if(index == 0){
  70. html.push(`<h2 class="category">${category}</h2><div class="items">`);
  71. }
  72. html.push(`<div class="item">`);
  73. html.push(`<div class="img" onclick="viewVideo(this,'./${category}/${pth}/video.mp4')">`);
  74. html.push(`<img src="./${category}/${pth}/img/${x2.slice(-1)[0].split(' ')[0]}" class="image-x2" />`);
  75. html.push(`</div>`);
  76. html.push(`<div class="title" onclick="window.open('${lnk}','_blank')">${tit}</div>`);
  77. html.push(`</div>`);
  78. commands.push(`@echo downloading ${encodeURI(src.join('/'))}`);
  79. commands.push(`@curl -o "${pth}\\img\\${src.slice(-1)[0]}" "${encodeURI(src.join('/')).replace(/%/g,'%%')}" 2>NUL`);
  80. commands.push(`@echo downloading ${encodeURI(x2.join('/').split(' ')[0])}`);
  81. commands.push(`@curl -o "${pth}\\img\\${x2.slice(-1)[0].split(' ')[0]}" "${encodeURI(x2.join('/').split(' ')[0]).replace(/%/g,'%%')}" 2>NUL`);
  82. commands.push(`@%25getpage%25 "${lnk}" "${category}\\${pth}" "${collect||category}"`);
  83. });
  84. if(items.length>0){
  85. html.push(`</div>`);
  86. }
  87. commands.push('@cd %25pwd%25');
  88. if(collect){
  89. return {category, commands, html}
  90. }else{
  91. let content = cmd == 'cmd' ? commands.join("\n") : html.join("\n");
  92. down(cmd, category, content)
  93. }
  94. }
  95. function down(cmd, category, content){
  96. let ele = document.createElement('a');
  97. ele.style.display = 'none';
  98. ele.setAttribute('href', 'data:text/plain;charset=utf-8,' + content);
  99. ele.setAttribute('download', category + '.' + cmd);
  100. document.body.appendChild(ele);
  101. ele.click();
  102. document.body.removeChild(ele);
  103. }
  104. function collect(cmd){
  105. let html = [];
  106. let commands = [];
  107. let cmdfile = 'Resources';
  108. let categories = document.querySelectorAll('.tutorialsBrowser__categoriesItem> .tutorialsBrowser__categoriesLink');
  109. let lproxy = localStorage.getItem('archiveAssistant_proxy');
  110. if(cmd=='cmd'){
  111. proxy = prompt("Input proxy string like http://127.0.0.1:8899, if no proxy keep it empty", lproxy || '');
  112. localStorage.setItem('archiveAssistant_proxy', proxy||'');
  113. }
  114. for(let i=0,il=categories.length;i<il;i++){
  115. categories[i].click();
  116. let source = getCategoryInfo(1, cmdfile, i==0);
  117. if(source.html.length>0){
  118. html = html.concat(source.html);
  119. }
  120. commands = commands.concat(source.commands);
  121. }
  122. html.push('</body></html>')
  123. down(cmd, cmdfile,(cmd=='cmd'?commands:html).join("\n"));
  124. }
  125.  
  126. (function() {
  127. 'use strict';
  128. GM_registerMenuCommand("get All Cmd", function(evt, keybord){
  129. collect('cmd');
  130. });
  131. GM_registerMenuCommand("get All HTML", function(evt, keybord){
  132. collect('html');
  133. });
  134. GM_registerMenuCommand("get Command", function(evt, keybord){
  135. proxy = prompt("Input proxy string like http://127.0.0.1:8899, if no proxy keep it empty", lproxy || '');
  136. localStorage.setItem('archiveAssistant_proxy', proxy||'');
  137. getCategoryInfo('cmd', false, true);
  138. });
  139. GM_registerMenuCommand("get HTML", function(evt, keybord){
  140. getCategoryInfo('html', false, true);
  141. });
  142. })();