Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
enoyee
Scriptable
提交
a1e1ffc2
S
Scriptable
项目概览
enoyee
/
Scriptable
通知
9
Star
0
Fork
3
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
Scriptable
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
a1e1ffc2
编写于
12月 09, 2022
作者:
AndroidLeaves
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update 写真
上级
dd6ce1d5
变更
3
展开全部
显示空白变更内容
内联
并排
Showing
3 changed file
with
375 addition
and
679 deletion
+375
-679
_LSP.js
_LSP.js
+11
-2
test.js
test.js
+114
-583
写真随机.js
写真随机.js
+250
-94
未找到文件。
_LSP.js
浏览文件 @
a1e1ffc2
...
@@ -1040,6 +1040,15 @@ class BaseWidget {
...
@@ -1040,6 +1040,15 @@ class BaseWidget {
return
index
return
index
}
}
getRandowArrValue
(
arr
)
{
const
key
=
parseInt
(
Math
.
random
()
*
arr
.
length
)
let
item
=
arr
[
key
]
if
(
item
==
undefined
)
{
item
=
arr
[
0
]
}
return
item
}
keySave
=
(
cacheKey
,
cache
)
=>
{
keySave
=
(
cacheKey
,
cache
)
=>
{
if
(
cache
)
{
if
(
cache
)
{
Keychain
.
set
(
cacheKey
,
cache
);
Keychain
.
set
(
cacheKey
,
cache
);
...
@@ -1755,9 +1764,9 @@ class BaseWidget {
...
@@ -1755,9 +1764,9 @@ class BaseWidget {
"
user-agent
"
:
"
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.67 Safari/537.36
"
"
user-agent
"
:
"
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.67 Safari/537.36
"
};
};
const
html
=
await
this
.
httpGet
(
url
,
{
jsonFromat
:
false
,
headers
});
const
html
=
await
this
.
httpGet
(
url
,
{
jsonFromat
:
false
,
headers
});
le
t
webview
=
new
WebView
();
cons
t
webview
=
new
WebView
();
await
webview
.
loadHTML
(
html
);
await
webview
.
loadHTML
(
html
);
var
getData
=
`
const
getData
=
`
function getData() {
function getData() {
try {
try {
infoLunarText = document.querySelector('div#wnrl_k_you_id_
${
day
}
.wnrl_k_you .wnrl_k_you_id_wnrl_nongli').innerText
infoLunarText = document.querySelector('div#wnrl_k_you_id_
${
day
}
.wnrl_k_you .wnrl_k_you_id_wnrl_nongli').innerText
...
...
test.js
浏览文件 @
a1e1ffc2
此差异已折叠。
点击以展开。
写真随机.js
浏览文件 @
a1e1ffc2
// Variables used by Scriptable.
// Variables used by Scriptable.
// These must be at the very top of the file. Do not edit.
// These must be at the very top of the file. Do not edit.
// icon-color:
yellow
; icon-glyph: user-astronaut;
// icon-color:
red
; icon-glyph: user-astronaut;
/**
/**
* Author:LSP
* Author:LSP
* Date:2022-1
1-05
* Date:2022-1
2-09
*/
*/
// @导入引用开发环境
// -------------------------------------------------------
// 是否是开发环境,配合手机端调试使用,正式发布设置为false
const
isDev
=
true
;
console
.
log
(
`开发环境 👉👉👉👉👉
${
isDev
?
'
DEV
'
:
'
RELEASE
'
}
`
);
console
.
log
(
`----------------------------------------`
);
const
remoteRoot
=
'
https://gitcode.net/enoyee/scriptable/-/raw/master/
'
;
// 依赖包目录
const
fm
=
FileManager
.
local
();
const
rootDir
=
fm
.
documentsDirectory
();
const
cacheDir
=
fm
.
joinPath
(
rootDir
,
'
LSP
'
);
const
dependencyFileName
=
isDev
?
"
_LSP.js
"
:
`
${
cacheDir
}
/_LSP.js`
;
// 下载依赖包
await
downloadLSPDependency
();
// -------------------------------------------------------
if
(
typeof
require
===
'
undefined
'
)
require
=
importModule
if
(
typeof
require
===
'
undefined
'
)
require
=
importModule
const
{
Base
}
=
require
(
"
./lsp环境
"
)
// 引入相关方法
const
{
BaseWidget
}
=
require
(
dependencyFileName
);
const
widgetConfigs
=
{
// 图片等分缓存key
picHalvingCacheKey
:
'
_halving
'
,
}
// @定义小组件
// @定义小组件
class
Widget
extends
Base
{
class
Widget
extends
BaseWidget
{
defaultPreference
=
{
photoHalving
:
'
1
'
,
sourceIndex
:
'
0
'
,
sourceArr
:
[
{
name
:
'
dopaminegirl
'
},
{
name
:
'
dounimei
'
},
]
};
getValueByKey
=
(
key
)
=>
this
.
readWidgetSetting
()[
key
]
??
this
.
defaultPreference
[
key
];
photoHalving
=
()
=>
this
.
getValueByKey
(
'
photoHalving
'
);
sourceIndex
=
()
=>
Number
(
this
.
getValueByKey
(
'
sourceIndex
'
));
sourceDesc
=
(
sourceIndex
)
=>
this
.
defaultPreference
.
sourceArr
[
sourceIndex
].
name
;
constructor
(
scriptName
)
{
constructor
(
scriptName
)
{
super
(
scriptName
)
super
(
scriptName
);
// @小组件配置
this
.
setModuleName
(
module
.
filename
);
// 初始化设置菜单
this
.
initWidgetSettingMenu
();
}
}
/**
async
getAppViewOptions
()
{
* 初始化设置菜单
return
{
*/
widgetProvider
:
{
async
initWidgetSettingMenu
()
{
small
:
true
,
// 是否提供小号组件
// 组件菜单点击
medium
:
true
,
// 是否提供中号组件
const
onMenuItemClick
=
async
(
item
)
=>
{
large
:
true
,
// 是否提供大号组件
switch
(
item
.
title
)
{
},
case
'
图片等分
'
:
// 预览界面的组件设置item
const
picHalvingCache
=
this
.
keyGet
(
widgetConfigs
.
picHalvingCacheKey
,
'
1
'
);
settingItems
:
[
await
this
.
generateInputAlert
(
'
图片等分设置
'
,
'
根据选择的大中小组件自己划分,最大值为4
'
,
'
请输入数字进行等分
'
,
picHalvingCache
,
(
content
)
=>
{
{
this
.
keySave
(
widgetConfigs
.
picHalvingCacheKey
,
content
);
name
:
'
photoHalving
'
,
});
label
:
'
图片等分
'
,
break
;
type
:
'
cell
'
,
}
icon
:
{
name
:
'
photo.artframe
'
,
color
:
'
#ffca3a
'
},
alert
:
{
title
:
'
图片等分设置
'
,
message
:
"
小组件显示多少张图片,最大值为4
"
,
options
:
[
{
key
:
'
photoHalving
'
,
hint
:
'
请输入数字进行等分
'
,
}
}
// 设置菜单
]
const
settingMenu
=
[
},
needLoading
:
false
,
default
:
this
.
photoHalving
(),
},
{
{
icon
:
{
name
:
'
photo.artframe
'
,
color
:
'
#E6AABB
'
,
cornerWidth
:
40
},
name
:
'
source
'
,
title
:
'
图片等分
'
,
label
:
'
图源选择
'
,
onClick
:
onMenuItemClick
type
:
'
cell
'
,
icon
:
{
name
:
'
tray
'
,
color
:
'
#7743DB
'
,
},
needLoading
:
false
,
default
:
this
.
sourceDesc
(
this
.
sourceIndex
()),
},
},
];
],
////////////////////////////////////////////////////////////////////////
// cell类型的item点击回调
this
.
configSetting
(
settingMenu
);
onItemClick
:
async
(
item
)
=>
{
}
let
widgetSetting
=
this
.
readWidgetSetting
();
let
insertDesc
;
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
switch
(
item
.
name
)
{
case
'
source
'
:
addStackImg
=
async
(
imgRes
,
imgStack
)
=>
{
const
ufm
=
this
.
useFileManager
();
if
(
imgRes
&&
imgRes
.
length
>
0
)
{
const
index
=
await
this
.
presentSheet
({
let
item
=
this
.
getRandowArrValue
(
imgRes
);
title
:
'
图源设置
'
,
let
imgUrl
=
item
.
url
;
message
:
'
⊱配置图片获取来源⊰
'
,
imgStack
.
url
=
imgUrl
;
options
:
this
.
defaultPreference
.
sourceArr
,
let
img
=
await
this
.
getImageByUrl
(
imgUrl
,
'
mirror
'
,
true
);
});
let
imgSpan
=
imgStack
.
addImage
(
img
);
widgetSetting
.
sourceIndex
=
`
${
index
}
`
imgSpan
.
applyFillingContentMode
();
insertDesc
=
this
.
sourceDesc
(
index
);
}
break
;
}
/**
* 小型组件
* @returns
*/
async
provideSmallWidget
()
{
return
await
this
.
provideWidget
(
'
小号
'
);
}
}
// 写入更新配置
/**
this
.
writeWidgetSetting
(
widgetSetting
);
* 中型组件
return
{
* @returns
desc
:
{
value
:
insertDesc
},
*/
};
async
provideMediumWidget
()
{
},
return
await
this
.
provideWidget
(
'
中号
'
)
;
}
;
}
}
/**
async
render
({
widgetSetting
,
family
})
{
* 大型组件
return
await
this
.
provideWidget
(
family
,
this
.
photoHalving
());
* @returns
*/
async
provideLargeWidget
()
{
return
await
this
.
provideWidget
(
'
大号
'
);
}
}
async
provideWidget
(
type
=
'
大号
'
)
{
async
provideWidget
(
widgetFamily
,
photoHalving
)
{
let
name
=
type
;
let
name
=
'
大号
'
;
const
widgetFamily
=
config
.
widgetFamily
;
switch
(
widgetFamily
)
{
switch
(
widgetFamily
)
{
case
'
small
'
:
case
'
small
'
:
name
=
'
小号
'
;
name
=
'
小号
'
;
...
@@ -100,19 +119,17 @@ class Widget extends Base {
...
@@ -100,19 +119,17 @@ class Widget extends Base {
case
'
medium
'
:
case
'
medium
'
:
name
=
'
中号
'
;
name
=
'
中号
'
;
break
;
break
;
case
'
large
'
:
name
=
'
大号
'
;
break
;
}
}
//=================================
//=================================
const
widget
=
new
ListWidget
();
const
widget
=
new
ListWidget
();
widget
.
setPadding
(
0
,
0
,
0
,
0
);
//=================================
//=================================
let
stack
=
widget
.
addStack
();
let
stack
=
widget
.
addStack
();
const
imgRes
=
await
this
.
httpGet
(
`https://dopaminegirl.com/api/posts/ranking?offset=
${
parseInt
(
Math
.
random
()
*
1000
)
+
100
}
`
);
const
imgRes
=
await
this
.
loadMirrorPhotoRes
(
this
.
sourceIndex
());
const
widgetWidth
=
this
.
getWidgetWidthSize
(
name
,
false
)
+
20
;
const
widgetSize
=
this
.
getWidgetSize
(
name
);
const
widgetWidth
=
widgetSize
.
width
+
8
*
Device
.
screenScale
();
// 图片等分
// 图片等分
const
picHalvingCache
=
Number
(
this
.
keyGet
(
widgetConfigs
.
picHalvingCacheKey
,
'
1
'
)
);
const
picHalvingCache
=
Number
(
photoHalving
);
let
imgStack
;
let
imgStack
;
switch
(
picHalvingCache
)
{
switch
(
picHalvingCache
)
{
case
2
:
case
2
:
...
@@ -175,19 +192,158 @@ class Widget extends Base {
...
@@ -175,19 +192,158 @@ class Widget extends Base {
return
widget
;
return
widget
;
}
}
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
addStackImg
=
async
(
imgRes
,
imgStack
)
=>
{
if
(
imgRes
&&
imgRes
.
length
>
0
)
{
let
item
=
this
.
getRandowArrValue
(
imgRes
);
let
imgUrl
=
item
.
url
;
imgStack
.
url
=
imgUrl
;
let
img
=
await
this
.
getImageByUrl
(
imgUrl
,
'
mirror
'
,
true
);
let
imgSpan
=
imgStack
.
addImage
(
img
);
imgSpan
.
applyFillingContentMode
();
}
}
// --------------------------NET START--------------------------
loadMirrorPhotoRes
=
async
(
source
=
0
)
=>
{
const
imgResArr
=
[];
switch
(
source
)
{
case
0
:
const
imgRes
=
await
this
.
httpGet
(
`https://dopaminegirl.com/api/posts/ranking?offset=
${
parseInt
(
Math
.
random
()
*
1000
)
+
100
}
`
);
imgRes
.
forEach
(
element
=>
{
imgResArr
.
push
({
url
:
element
.
url
});
});
break
;
case
1
:
// 抖你妹数据
const
url
=
`https://www.dounimei.co/page/
${
parseInt
(
Math
.
random
()
*
80
)
+
1
}
?orderby=hot`
;
const
headers
=
{
"
user-agent
"
:
"
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.67 Safari/537.36
"
};
const
webview
=
new
WebView
();
const
html
=
await
this
.
httpGet
(
url
,
{
jsonFromat
:
false
,
headers
});
await
webview
.
loadHTML
(
html
);
const
getData
=
`
function getData() {
let imgArr = [];
try {
let imgData = document.getElementsByTagName('img');
for (let index = 0; index < imgData.length; index++) {
let elementSrc = imgData[index].getAttribute("data-src");
if(elementSrc != null && elementSrc != undefined) {
let start = elementSrc.indexOf('?src=');
let end = elementSrc.lastIndexOf('&h');
imgArr.push({url : elementSrc.slice(start + 5, end)});
}
}
} catch(e) {
console.log('抖你妹资源获取出错->' + e);
}
return imgArr;
}
getData();
`
const
dounimeiRes
=
await
webview
.
evaluateJavaScript
(
getData
,
false
);
dounimeiRes
.
forEach
(
element
=>
{
imgResArr
.
push
({
url
:
element
.
url
});
});
break
;
}
return
imgResArr
;
}
// --------------------------NET END--------------------------
}
}
// @运行测试
await
new
Widget
(
Script
.
name
()).
run
();
const
{
Running
}
=
require
(
"
./lsp环境
"
)
const
newConfig
=
{
visualMode
:
true
,
// =================================================================================
small
:
true
,
// =================================================================================
medium
:
true
,
async
function
downloadLSPDependency
()
{
large
:
true
,
let
fm
=
FileManager
.
local
();
accessoryCircular
:
false
,
const
dependencyURL
=
`
${
remoteRoot
}
_LSP.js`
;
accessoryRectangular
:
false
,
if
(
isDev
)
{
accessoryInline
:
false
const
iCloudPath
=
FileManager
.
iCloud
().
documentsDirectory
();
const
localIcloudDependencyExit
=
fm
.
isFileStoredIniCloud
(
`
${
iCloudPath
}
/_LSP.js`
);
const
localDependencyExit
=
fm
.
fileExists
(
`
${
rootDir
}
/_LSP.js`
);
const
fileExist
=
localIcloudDependencyExit
||
localDependencyExit
;
console
.
log
(
`🚀 DEV开发依赖文件
${
fileExist
?
'
已存在 ✅
'
:
'
不存在 🚫
'
}
`
);
if
(
!
fileExist
)
{
console
.
log
(
`🤖 DEV 开始下载依赖~`
);
await
downloadFile2Scriptable
(
'
_LSP
'
,
dependencyURL
);
}
return
}
//////////////////////////////////////////////////////////
console
.
log
(
`----------------------------------------`
);
const
remoteDependencyExit
=
fm
.
fileExists
(
`
${
cacheDir
}
/_LSP.js`
);
console
.
log
(
`🚀 RELEASE依赖文件
${
remoteDependencyExit
?
'
已存在 ✅
'
:
'
不存在 🚫
'
}
`
);
console
.
log
(
`----------------------------------------`
);
// ------------------------------
if
(
!
remoteDependencyExit
)
{
// 下载依赖
// 创建根目录
if
(
!
fm
.
fileExists
(
cacheDir
))
{
fm
.
createDirectory
(
cacheDir
,
true
);
}
// 下载
console
.
log
(
'
🤖 RELEASE开始下载依赖~
'
);
console
.
log
(
`----------------------------------------`
);
const
req
=
new
Request
(
dependencyURL
);
const
moduleJs
=
await
req
.
load
();
if
(
moduleJs
)
{
fm
.
write
(
fm
.
joinPath
(
cacheDir
,
'
/_LSP.js
'
),
moduleJs
);
console
.
log
(
'
✅ LSP远程依赖环境下载成功!
'
);
console
.
log
(
`----------------------------------------`
);
}
else
{
console
.
error
(
'
🚫 获取依赖环境脚本失败,请重试!
'
);
console
.
log
(
`----------------------------------------`
);
}
}
}
/**
* 获取保存的文件名
* @param {*} fileName
* @returns
*/
function
getSaveFileName
(
fileName
)
{
const
hasSuffix
=
fileName
.
lastIndexOf
(
"
.
"
)
+
1
;
return
!
hasSuffix
?
`
${
fileName
}
.js`
:
fileName
;
};
/**
* 保存文件到Scriptable软件目录,app可看到
* @param {*} fileName
* @param {*} content
* @returns
*/
function
saveFile2Scriptable
(
fileName
,
content
)
{
try
{
const
fm
=
FileManager
.
iCloud
();
let
fileSimpleName
=
getSaveFileName
(
fileName
);
const
filePath
=
fm
.
joinPath
(
fm
.
documentsDirectory
(),
fileSimpleName
);
fm
.
writeString
(
filePath
,
content
);
return
true
;
}
catch
(
error
)
{
return
false
;
}
};
};
await
Running
(
Widget
,
Script
.
name
(),
true
,
newConfig
)
\ No newline at end of file
/**
* 下载js文件到Scriptable软件目录
* @param {*} moduleName 名称
* @param {*} url 在线地址
* @returns
*/
async
function
downloadFile2Scriptable
(
moduleName
,
url
)
{
const
req
=
new
Request
(
url
);
const
content
=
await
req
.
loadString
();
return
saveFile2Scriptable
(
`
${
moduleName
}
`
,
content
);
};
// =================================================================================
// =================================================================================
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录