pixelmatorTutorialDownloader

download pixcelmator pro tutorial resouces and youtube videos to local disk

当前为 2023-04-02 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name pixelmatorTutorialDownloader
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.15
  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. // @match https://www.pixelmator.com/support/guide/pixelmator-pro/*
  9. // @icon https://www.google.com/s2/favicons?sz=64&domain=pixelmator.com
  10. // @run-at document-end
  11. // @grant GM_registerMenuCommand
  12. // @license MIT
  13. // ==/UserScript==
  14.  
  15. let proxy = '';
  16.  
  17. function getCategoryInfo(cmd, collect, init){
  18. let category = document.querySelector('.tutorialsBrowser__categoriesList >.tutorialsBrowser__categoriesItem.is-active').innerText;
  19. let moreless = document.querySelector('.tutorialsBrowser__mainCategoryMore>.tutorialsBrowser__mainCategoryMoreBtn');
  20. let commands = [];
  21. let download = [];
  22. let html = [];
  23. let foldmap = {};
  24. if(!moreless.parentElement.classList.contains('is-inactive')){
  25. moreless.click();
  26. }
  27. if(init){
  28. commands.push('cls');
  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+ba" --progress ${proxy?'--proxy "'+proxy+'"':''} --no-playlist --restrict-filenames --write-subs --audio-quality 10 --merge-output-format "mp4" --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 ${proxy||'.'} > "%25~dp0\\assets\\proxy.conf"`);
  52. commands.push(`@echo @echo tutorial resource downloader ${init?'>':'>>'} %25~dp0\\${collect||category}_res.cmd`);
  53. commands.push(`@echo @title %25cd%25 >> %25~dp0\\${collect||category}_res.cmd`);
  54. commands.push(`@echo @title %25cd%25 >> %25~dp0\\${collect||category}_ytb.cmd`);
  55. }
  56. commands.push(`@if not exist ${category} mkdir ${category}`);
  57. commands.push(`@cd ${category}`);
  58. let items = document.querySelectorAll('.tutorialsBrowser__mainCategoryList >.tutorialsBrowser__mainItem');
  59. items.forEach((item,index)=>{
  60. let img = item.querySelector('.tutorialsThumbnail__image');
  61. let lnk = item.querySelector('.tutorialsThumbnail__link').href;
  62. let tit = item.querySelector('.tutorialsThumbnail__title').innerText;
  63. let src = 'https:'+img.getAttribute('src').replace(/^https?:/i,'');
  64. let x2 = 'https:'+img.getAttribute('srcset').replace(/^https?:/i,'');
  65. let pth = lnk.split('/').slice(-2,-1)[0];
  66. src = src.split('/');
  67. x2 = x2.split('/');
  68. if(!foldmap[pth]){
  69. foldmap[pth] = 1;
  70. commands.push(`@if not exist "${pth}\\img" mkdir "${pth}\\img"`);
  71. }
  72. if(index == 0){
  73. html.push(`<h2 class="category">${category}</h2><div class="items">`);
  74. }
  75. html.push(`<div class="item">`);
  76. html.push(`<div class="img" onclick="viewVideo(this,'./${category}/${pth}/video.mp4')">`);
  77. html.push(`<img src="./${category}/${pth}/img/${x2.slice(-1)[0].split(' ')[0]}" class="image-x2" />`);
  78. html.push(`</div>`);
  79. html.push(`<div class="title" onclick="window.open('${lnk}','_blank')">${tit}</div>`);
  80. html.push(`</div>`);
  81. let img1 = `${pth}\\img\\${src.slice(-1)[0]}`,
  82. url1 = `${encodeURI(src.join('/')).replace(/%/g,'%%')}`;
  83. commands.push(`@rem downloading ${encodeURI(src.join('/'))}`);
  84. commands.push(`@if not exist "${img1}" @curl -o "${img1}" "${url1}" 2>NUL`);
  85. let img2 = `${pth}\\img\\${x2.slice(-1)[0].split(' ')[0]}`,
  86. url2 = `${encodeURI(x2.join('/').split(' ')[0]).replace(/%/g,'%%')}`;
  87. commands.push(`@rem downloading ${encodeURI(x2.join('/').split(' ')[0])}`);
  88. commands.push(`@if not exist "${img2}" @curl -o "${img2}" "${url2}" 2>NUL`);
  89. commands.push(`@%25getpage%25 "${lnk}" "${category}\\${pth}" "${collect||category}"`);
  90. commands.push(`@cd %25~dp0`);
  91. });
  92. if(items.length>0){
  93. html.push(`</div>`);
  94. }
  95. commands.push('@cd %25~dp0');
  96. if(collect){
  97. return {category, commands, html}
  98. }else{
  99. let content = cmd == 'cmd' ? commands.join("\n") : html.join("\n");
  100. down(cmd, category, content)
  101. }
  102. }
  103.  
  104. function getGuideCmd(){
  105. let guides = document.querySelectorAll('.guides-menu a');
  106. let cmds = [];
  107. cmds.push('cls');
  108. cmds.push('@set getpage=%25~dp0\\..\\getpage.exe');
  109. cmds.push(`@if not exist %25~dp0guide mkdir %25~dp0guide`);
  110. let lproxy = localStorage.getItem('pixelmatorTutorialDownloader_proxy');
  111. proxy = prompt("Input proxy string like http://127.0.0.1:8899, if no proxy keep it empty", lproxy || '');
  112. localStorage.setItem('pixelmatorTutorialDownloader_proxy', proxy||'');
  113. cmds.push(`@echo ${proxy||'.'} > "%25~dp0\\assets\\proxy.conf"`);
  114. for(let i=0,il=guides.length; i<il; i++){
  115. let guide = guides[i];
  116. let match = guide.getAttribute('href').match(/\/pixelmator-pro\/(\d+)/)
  117. if(!guide.parentElement.classList.contains('openable') && match){
  118. cmds.push(`@if not exist "%25~dp0guide\\${match[1]}" mkdir "%25~dp0guide\\${match[1]}\\img"`);
  119. cmds.push(`@cd %25~dp0guide`);
  120. cmds.push([
  121. '@%25getpage%25',
  122. `"${guide.href}"`,
  123. `"guide\\${match[1]}"`,
  124. `"${guide.innerText.replace(/\"/g,'')}"`
  125. ].join(' '));
  126. }
  127. }
  128. down('cmd', 'Guides', cmds.join("\n"))
  129. }
  130. function down(cmd, category, content){
  131. let ele = document.createElement('a');
  132. ele.style.display = 'none';
  133. ele.setAttribute('href', 'data:text/plain;charset=utf-8,' + content);
  134. ele.setAttribute('download', category + '.' + cmd);
  135. document.body.appendChild(ele);
  136. ele.click();
  137. document.body.removeChild(ele);
  138. }
  139. function collect(cmd){
  140. let html = [];
  141. let commands = [];
  142. let cmdfile = 'Resources';
  143. let categories = document.querySelectorAll('.tutorialsBrowser__categoriesItem> .tutorialsBrowser__categoriesLink');
  144. let lproxy = localStorage.getItem('pixelmatorTutorialDownloader_proxy');
  145. if(cmd=='cmd'){
  146. proxy = prompt("Input proxy string like http://127.0.0.1:8899, if no proxy keep it empty", lproxy || '');
  147. localStorage.setItem('pixelmatorTutorialDownloader_proxy', proxy||'');
  148. }
  149. for(let i=0,il=categories.length;i<il;i++){
  150. categories[i].click();
  151. let source = getCategoryInfo(1, cmdfile, i==0);
  152. if(source.html.length>0){
  153. html = html.concat(source.html);
  154. }
  155. commands = commands.concat(source.commands);
  156. }
  157. html.push('</body></html>')
  158. down(cmd, cmdfile,(cmd=='cmd'?commands:html).join("\n"));
  159. }
  160.  
  161. (function() {
  162. 'use strict';
  163. GM_registerMenuCommand("get All Command", function(evt, keybord){
  164. collect('cmd');
  165. });
  166. GM_registerMenuCommand("get All HTML", function(evt, keybord){
  167. collect('html');
  168. });
  169. GM_registerMenuCommand("get Category Command", function(evt, keybord){
  170. let lproxy = localStorage.getItem('pixelmatorTutorialDownloader_proxy');
  171. proxy = prompt("Input proxy string like http://127.0.0.1:8899, if no proxy keep it empty", lproxy || '');
  172. localStorage.setItem('archiveAssistant_proxy', proxy||'');
  173. getCategoryInfo('cmd', false, true);
  174. });
  175. GM_registerMenuCommand("get Category HTML", function(evt, keybord){
  176. getCategoryInfo('html', false, true);
  177. });
  178. GM_registerMenuCommand("get User Guides", function(evt, keybord){
  179. getGuideCmd();
  180. });
  181. })();