pixelmatorTutorialDownloader

download pixcelmator pro tutorial resouces and youtube videos to local disk

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

  1. // ==UserScript==
  2. // @name pixelmatorTutorialDownloader
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.13
  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 getpage=%25~dp0\\..\\getpage.exe');
  29. 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`);
  30. html.push(`<!doctype html>`);
  31. html.push(`<html lang="en-US">`)
  32. html.push(`<head>`)
  33. html.push(`<meta charset="utf-8"/>`)
  34. html.push(`<title>Pixelmator Pro Tutorial</title>`)
  35. html.push(`<meta name="author" content="mooring@codernote.club"/>`)
  36. html.push(`<meta name="description" content="Pixelmator Pro Tutorial"/>`)
  37. html.push(`<meta name="viewport" content="width=device-width, initial-scale=1"/>`)
  38. html.push(`<style>`);
  39. html.push(`h2.category {width: 80%;display: block;border-bottom: 1px dodgerblue dotted;margin: 0.5em auto;padding-bottom: 0.5em;}`);
  40. html.push(`.items {width: 80%;margin: 0 auto;display: flex;flex-wrap: wrap;justify-content:flex-start}`);
  41. html.push(`.item {width:23.7em;padding:10px}`);
  42. html.push(`.img {width: 100%;height: 13em;cursor:pointer;position:relative;}`);
  43. 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;}`);
  44. html.push(`.title {font-weight:600;cursor:pointer;text-align: center;font-size: 1.2em;padding-bottom: 1em;}`);
  45. html.push(`img.image-x2 {width: 100%;height: 100%;border-radius: 1em;}`);
  46. html.push(`</style>`);
  47. html.push(`<script>`);
  48. 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");}`);
  49. html.push(`</script></head><body>`);
  50. commands.push(`@echo ${proxy||'.'} > "%25~dp0\\assets\\proxy.conf"`);
  51. commands.push(`@echo @echo tutorial resource downloader ${init?'>':'>>'} %25~dp0\\${collect||category}_res.cmd`);
  52. commands.push(`@echo @title %25cd%25 >> %25~dp0\\${collect||category}_res.cmd`);
  53. commands.push(`@echo @title %25cd%25 >> %25~dp0\\${collect||category}_ytb.cmd`);
  54. }
  55. commands.push(`@if not exist ${category} mkdir ${category}`);
  56. commands.push(`@cd ${category}`);
  57. let items = document.querySelectorAll('.tutorialsBrowser__mainCategoryList >.tutorialsBrowser__mainItem');
  58. items.forEach((item,index)=>{
  59. let img = item.querySelector('.tutorialsThumbnail__image');
  60. let lnk = item.querySelector('.tutorialsThumbnail__link').href;
  61. let tit = item.querySelector('.tutorialsThumbnail__title').innerText;
  62. let src = 'https:'+img.getAttribute('src').replace(/^https?:/i,'');
  63. let x2 = 'https:'+img.getAttribute('srcset').replace(/^https?:/i,'');
  64. let pth = lnk.split('/').slice(-2,-1)[0];
  65. src = src.split('/');
  66. x2 = x2.split('/');
  67. if(!foldmap[pth]){
  68. foldmap[pth] = 1;
  69. commands.push(`@if not exist "${pth}\\img" mkdir "${pth}\\img"`);
  70. }
  71. if(index == 0){
  72. html.push(`<h2 class="category">${category}</h2><div class="items">`);
  73. }
  74. html.push(`<div class="item">`);
  75. html.push(`<div class="img" onclick="viewVideo(this,'./${category}/${pth}/video.mp4')">`);
  76. html.push(`<img src="./${category}/${pth}/img/${x2.slice(-1)[0].split(' ')[0]}" class="image-x2" />`);
  77. html.push(`</div>`);
  78. html.push(`<div class="title" onclick="window.open('${lnk}','_blank')">${tit}</div>`);
  79. html.push(`</div>`);
  80. let img1 = `${pth}\\img\\${src.slice(-1)[0]}`,
  81. url1 = `${encodeURI(src.join('/')).replace(/%/g,'%%')}`;
  82. commands.push(`@rem downloading ${encodeURI(src.join('/'))}`);
  83. commands.push(`@if not exist "${img1}" @curl -o "${img1}" "${url1}" 2>NUL`);
  84. let img2 = `${pth}\\img\\${x2.slice(-1)[0].split(' ')[0]}`,
  85. url2 = `${encodeURI(x2.join('/').split(' ')[0]).replace(/%/g,'%%')}`;
  86. commands.push(`@rem downloading ${encodeURI(x2.join('/').split(' ')[0])}`);
  87. commands.push(`@if not exist "${img2}" @curl -o "${img2}" "${url2}" 2>NUL`);
  88. commands.push(`@%25getpage%25 "${lnk}" "${category}\\${pth}" "${collect||category}"`);
  89. });
  90. if(items.length>0){
  91. html.push(`</div>`);
  92. }
  93. commands.push('@cd %25~dp0');
  94. if(collect){
  95. return {category, commands, html}
  96. }else{
  97. let content = cmd == 'cmd' ? commands.join("\n") : html.join("\n");
  98. down(cmd, category, content)
  99. }
  100. }
  101. function down(cmd, category, content){
  102. let ele = document.createElement('a');
  103. ele.style.display = 'none';
  104. ele.setAttribute('href', 'data:text/plain;charset=utf-8,' + content);
  105. ele.setAttribute('download', category + '.' + cmd);
  106. document.body.appendChild(ele);
  107. ele.click();
  108. document.body.removeChild(ele);
  109. }
  110. function collect(cmd){
  111. let html = [];
  112. let commands = [];
  113. let cmdfile = 'Resources';
  114. let categories = document.querySelectorAll('.tutorialsBrowser__categoriesItem> .tutorialsBrowser__categoriesLink');
  115. let lproxy = localStorage.getItem('pixelmatorTutorialDownloader_proxy');
  116. if(cmd=='cmd'){
  117. proxy = prompt("Input proxy string like http://127.0.0.1:8899, if no proxy keep it empty", lproxy || '');
  118. localStorage.setItem('pixelmatorTutorialDownloader_proxy', proxy||'');
  119. }
  120. for(let i=0,il=categories.length;i<il;i++){
  121. categories[i].click();
  122. let source = getCategoryInfo(1, cmdfile, i==0);
  123. if(source.html.length>0){
  124. html = html.concat(source.html);
  125. }
  126. commands = commands.concat(source.commands);
  127. }
  128. html.push('</body></html>')
  129. down(cmd, cmdfile,(cmd=='cmd'?commands:html).join("\n"));
  130. }
  131.  
  132. (function() {
  133. 'use strict';
  134. GM_registerMenuCommand("get All Command", function(evt, keybord){
  135. collect('cmd');
  136. });
  137. GM_registerMenuCommand("get All HTML", function(evt, keybord){
  138. collect('html');
  139. });
  140. GM_registerMenuCommand("get Category Command", function(evt, keybord){
  141. let lproxy = localStorage.getItem('pixelmatorTutorialDownloader_proxy');
  142. proxy = prompt("Input proxy string like http://127.0.0.1:8899, if no proxy keep it empty", lproxy || '');
  143. localStorage.setItem('archiveAssistant_proxy', proxy||'');
  144. getCategoryInfo('cmd', false, true);
  145. });
  146. GM_registerMenuCommand("get Category HTML", function(evt, keybord){
  147. getCategoryInfo('html', false, true);
  148. });
  149. })();