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.04
  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. commands.push(`@echo. ${init?'>':'>>'} ..\\pages.md`);
  56. commands.push(`@echo Just text tutorial Pages of ${category} >> ..\\pages.md`);
  57. commands.push(`@echo -------------------------------------------------- >> ..\\pages.md`);
  58. commands.push(`@echo. >> ..\\pages.md`);
  59. let items = document.querySelectorAll('.tutorialsBrowser__mainCategoryList >.tutorialsBrowser__mainItem');
  60. items.forEach((item,index)=>{
  61. let img = item.querySelector('.tutorialsThumbnail__image');
  62. let lnk = item.querySelector('.tutorialsThumbnail__link').href;
  63. let tit = item.querySelector('.tutorialsThumbnail__title').innerText;
  64. let src = 'https:'+img.getAttribute('src').replace(/^https?:/i,'');
  65. let x2 = 'https:'+img.getAttribute('srcset').replace(/^https?:/i,'');
  66. let pth = lnk.split('/').slice(-2,-1)[0];
  67. src = src.split('/');
  68. x2 = x2.split('/');
  69. if(!foldmap[pth]){
  70. foldmap[pth] = 1;
  71. commands.push(`@if not exist "${pth}\\img" mkdir "${pth}\\img"`);
  72. }
  73. if(index == 0){
  74. html.push(`<h2 class="category">${category}</h2><div class="items">`);
  75. }
  76. html.push(`<div class="item">`);
  77. html.push(`<div class="img" onclick="viewVideo(this,'./${category}/${pth}/video.mp4')">`);
  78. html.push(`<img src="./${category}/${pth}/img/${x2.slice(-1)[0].split(' ')[0]}" class="image-x2" />`);
  79. html.push(`</div>`);
  80. html.push(`<div class="title" onclick="window.open('${lnk}','_blank')">${tit}</div>`);
  81. html.push(`</div>`);
  82. commands.push(`@echo downloading ${encodeURI(src.join('/'))}`);
  83. commands.push(`@curl -o "${pth}\\img\\${src.slice(-1)[0]}" "${encodeURI(src.join('/')).replace(/%/g,'%%')}" 2>NUL`);
  84. commands.push(`@echo downloading ${encodeURI(x2.join('/').split(' ')[0])}`);
  85. commands.push(`@curl -o "${pth}\\img\\${x2.slice(-1)[0].split(' ')[0]}" "${encodeURI(x2.join('/').split(' ')[0]).replace(/%/g,'%%')}" 2>NUL`);
  86. commands.push(`@%25getpage%25 "${lnk}" "${category}\\${pth}" "${collect||category}"`);
  87. });
  88. if(items.length>0){
  89. html.push(`</div>`);
  90. }
  91. commands.push('@cd %25pwd%25');
  92. if(collect){
  93. return {category, commands, html}
  94. }else{
  95. let content = cmd == 'cmd' ? commands.join("\n") : html.join("\n");
  96. down(cmd, category, content)
  97. }
  98. }
  99. function down(cmd, category, content){
  100. let ele = document.createElement('a');
  101. ele.style.display = 'none';
  102. ele.setAttribute('href', 'data:text/plain;charset=utf-8,' + content);
  103. ele.setAttribute('download', category + '.' + cmd);
  104. document.body.appendChild(ele);
  105. ele.click();
  106. document.body.removeChild(ele);
  107. }
  108. function collect(cmd){
  109. let html = [];
  110. let commands = [];
  111. let cmdfile = 'Resources';
  112. let categories = document.querySelectorAll('.tutorialsBrowser__categoriesItem> .tutorialsBrowser__categoriesLink');
  113. let lproxy = localStorage.getItem('archiveAssistant_proxy');
  114. if(cmd=='cmd'){
  115. proxy = prompt("Input proxy string like http://127.0.0.1:8899, if no proxy keep it empty", lproxy || '');
  116. localStorage.setItem('archiveAssistant_proxy', proxy||'');
  117. }
  118. for(let i=0,il=categories.length;i<il;i++){
  119. categories[i].click();
  120. let source = getCategoryInfo(1, cmdfile, i==0);
  121. if(source.html.length>0){
  122. html = html.concat(source.html);
  123. }
  124. commands = commands.concat(source.commands);
  125. }
  126. html.push('</body></html>')
  127. down(cmd, cmdfile,(cmd=='cmd'?commands:html).join("\n"));
  128. }
  129.  
  130. (function() {
  131. 'use strict';
  132. GM_registerMenuCommand("get All Cmd", function(evt, keybord){
  133. collect('cmd');
  134. });
  135. GM_registerMenuCommand("get All HTML", function(evt, keybord){
  136. collect('html');
  137. });
  138. GM_registerMenuCommand("get Command", function(evt, keybord){
  139. proxy = prompt("Input proxy string like http://127.0.0.1:8899, if no proxy keep it empty", lproxy || '');
  140. localStorage.setItem('archiveAssistant_proxy', proxy||'');
  141. getCategoryInfo('cmd', false, true);
  142. });
  143. GM_registerMenuCommand("get HTML", function(evt, keybord){
  144. getCategoryInfo('html', false, true);
  145. });
  146. })();