11// ==UserScript==
22// @name pixelmatorTutorialDownloader
33// @namespace http://tampermonkey.net/
4- // @version 0.15
4+ // @version 0.16
55// @description download pixcelmator pro tutorial resouces and youtube videos to local disk
66// @author mooring@codernote.club
77// @match https://www.pixelmator.com/tutorials/*
@@ -25,9 +25,15 @@ function getCategoryInfo(cmd, collect, init){
2525 moreless . click ( ) ;
2626 }
2727 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` ) ;
28+ commands . push ( `cls` ) ;
29+ commands . push ( `@set proxy=` ) ;
30+ commands . push ( `@set proxy=${ proxy } ` ) ;
31+ commands . push ( `@set pxystr=` )
32+ commands . push ( `@if "%25proxy%25" == "" @echo.>"%25~dp0assets\\proxy.conf"` ) ;
33+ commands . push ( `@if not "%25proxy%25" == "" @echo %25proxy%25>"%25~dp0assets\\proxy.conf"` ) ;
34+ commands . push ( `@if not "%25proxy%25" == "" @set pxystr=--proxy "%25proxy%25"` ) ;
35+ commands . push ( `@set getpage=%25~dp0..\\bin\\getpage.exe` ) ;
36+ commands . push ( `@echo @set down=..\\bin\\yt-dlp --write-thumbnail --embed-metadata --cache-dir cache --write-link -f "bv+ba" --progress %25pxystr%25 --no-playlist --restrict-filenames --write-subs --audio-quality 10 --merge-output-format "mp4" --sub-langs "en-US.*,zh-Hans.*" --convert-thumbnails png --ffmpeg-location ..\\bin ${ init ?'>' :'>>' } %25~dp0${ collect || category } _ytb.cmd` ) ;
3137 html . push ( `<!doctype html>` ) ;
3238 html . push ( `<html lang="en-US">` )
3339 html . push ( `<head>` )
@@ -48,13 +54,13 @@ function getCategoryInfo(cmd, collect, init){
4854 html . push ( `<script>` ) ;
4955 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");}` ) ;
5056 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` ) ;
57+ commands . push ( `@echo @echo resource downloader ${ init ?'>' :'>>' } %25~dp0${ collect || category } _res.cmd` ) ;
58+ commands . push ( `@echo @title %25cd%25 >> %25~dp0${ collect || category } _res.cmd` ) ;
59+ commands . push ( `@echo @title %25cd%25 >> %25~dp0${ collect || category } _ytb.cmd` ) ;
5560 }
56- commands . push ( `@if not exist ${ category } mkdir ${ category } ` ) ;
57- commands . push ( `@cd ${ category } ` ) ;
61+ commands . push ( `@cd %25~dp0` ) ;
62+ commands . push ( `@if not exist %25~dp0${ category } mkdir %25~dp0${ category } ` ) ;
63+ commands . push ( `@cd %25~dp0${ category } ` ) ;
5864 let items = document . querySelectorAll ( '.tutorialsBrowser__mainCategoryList >.tutorialsBrowser__mainItem' ) ;
5965 items . forEach ( ( item , index ) => {
6066 let img = item . querySelector ( '.tutorialsThumbnail__image' ) ;
@@ -87,7 +93,6 @@ function getCategoryInfo(cmd, collect, init){
8793 commands . push ( `@rem downloading ${ encodeURI ( x2 . join ( '/' ) . split ( ' ' ) [ 0 ] ) } ` ) ;
8894 commands . push ( `@if not exist "${ img2 } " @curl -o "${ img2 } " "${ url2 } " 2>NUL` ) ;
8995 commands . push ( `@%25getpage%25 "${ lnk } " "${ category } \\${ pth } " "${ collect || category } "` ) ;
90- commands . push ( `@cd %25~dp0` ) ;
9196 } ) ;
9297 if ( items . length > 0 ) {
9398 html . push ( `</div>` ) ;
@@ -104,13 +109,18 @@ function getCategoryInfo(cmd, collect, init){
104109function getGuideCmd ( ) {
105110 let guides = document . querySelectorAll ( '.guides-menu a' ) ;
106111 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` ) ;
110112 let lproxy = localStorage . getItem ( 'pixelmatorTutorialDownloader_proxy' ) ;
111113 proxy = prompt ( "Input proxy string like http://127.0.0.1:8899, if no proxy keep it empty" , lproxy || '' ) ;
112114 localStorage . setItem ( 'pixelmatorTutorialDownloader_proxy' , proxy || '' ) ;
113- cmds . push ( `@echo ${ proxy || '.' } > "%25~dp0\\assets\\proxy.conf"` ) ;
115+ cmds . push ( `cls` ) ;
116+ cmds . push ( `@set proxy=` ) ;
117+ cmds . push ( `@set proxy=${ proxy } ` ) ;
118+ cmds . push ( `@set pxystr=` )
119+ cmds . push ( `@if "%25proxy%25" == "" @echo.>"%25~dp0assets\\proxy.conf"` ) ;
120+ cmds . push ( `@if not "%25proxy%25" == "" @echo %25proxy%25>"%25~dp0assets\\proxy.conf"` ) ;
121+ cmds . push ( `@if not "%25proxy%25" == "" @set pxystr=--proxy "%25proxy%25"` ) ;
122+ cmds . push ( `@set getpage=%25~dp0..\\bin\\getpage.exe` ) ;
123+ cmds . push ( `@if not exist %25~dp0guide mkdir %25~dp0guide` ) ;
114124 for ( let i = 0 , il = guides . length ; i < il ; i ++ ) {
115125 let guide = guides [ i ] ;
116126 let match = guide . getAttribute ( 'href' ) . match ( / \/ p i x e l m a t o r - p r o \/ ( \d + ) / )
0 commit comments