publishport-opencli 1.8.5-pp.35 → 1.8.5-pp.36
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cli-manifest.json +151 -10
- package/clis/dianping/auth.js +8 -9
- package/clis/dianping/cityResolver.js +4 -1
- package/clis/dianping/search.js +1 -1
- package/clis/facebook/comment.js +18 -0
- package/clis/facebook/like.js +29 -0
- package/clis/hackernews/comment.js +61 -0
- package/clis/hackernews/submit.js +65 -0
- package/clis/jimeng/auth.js +2 -2
- package/clis/jimeng/generate.js +53 -46
- package/clis/jimeng/history.js +22 -13
- package/clis/pixiv/auth.js +7 -16
- package/clis/suno/auth.js +13 -17
- package/package.json +1 -1
package/cli-manifest.json
CHANGED
|
@@ -14689,6 +14689,40 @@
|
|
|
14689
14689
|
"sourceFile": "facebook/add-friend.js",
|
|
14690
14690
|
"navigateBefore": "https://www.facebook.com"
|
|
14691
14691
|
},
|
|
14692
|
+
{
|
|
14693
|
+
"site": "facebook",
|
|
14694
|
+
"name": "comment",
|
|
14695
|
+
"description": "Post a comment on a Facebook post. Pass the post URL and the comment text (multi-line allowed). The comment is published from your logged-in account — write a genuine, on-topic remark, not filler.",
|
|
14696
|
+
"access": "write",
|
|
14697
|
+
"domain": "facebook.com",
|
|
14698
|
+
"strategy": "cookie",
|
|
14699
|
+
"browser": true,
|
|
14700
|
+
"args": [
|
|
14701
|
+
{
|
|
14702
|
+
"name": "url",
|
|
14703
|
+
"type": "string",
|
|
14704
|
+
"required": true,
|
|
14705
|
+
"positional": true,
|
|
14706
|
+
"help": "Post URL (e.g. https://www.facebook.com/<user>/posts/<id> or a permalink)"
|
|
14707
|
+
},
|
|
14708
|
+
{
|
|
14709
|
+
"name": "text",
|
|
14710
|
+
"type": "string",
|
|
14711
|
+
"required": true,
|
|
14712
|
+
"positional": true,
|
|
14713
|
+
"help": "Comment text (multi-line allowed)"
|
|
14714
|
+
}
|
|
14715
|
+
],
|
|
14716
|
+
"columns": [
|
|
14717
|
+
"status",
|
|
14718
|
+
"url",
|
|
14719
|
+
"message"
|
|
14720
|
+
],
|
|
14721
|
+
"type": "js",
|
|
14722
|
+
"modulePath": "facebook/comment.js",
|
|
14723
|
+
"sourceFile": "facebook/comment.js",
|
|
14724
|
+
"navigateBefore": "https://facebook.com"
|
|
14725
|
+
},
|
|
14692
14726
|
{
|
|
14693
14727
|
"site": "facebook",
|
|
14694
14728
|
"name": "events",
|
|
@@ -14826,6 +14860,41 @@
|
|
|
14826
14860
|
"sourceFile": "facebook/join-group.js",
|
|
14827
14861
|
"navigateBefore": "https://www.facebook.com"
|
|
14828
14862
|
},
|
|
14863
|
+
{
|
|
14864
|
+
"site": "facebook",
|
|
14865
|
+
"name": "like",
|
|
14866
|
+
"description": "Like a Facebook post (ends in the liked state; no-op if already liked). Pass the post URL. Reacts as a genuine like from your logged-in account — use it to engage with content you actually mean to endorse.",
|
|
14867
|
+
"access": "write",
|
|
14868
|
+
"domain": "facebook.com",
|
|
14869
|
+
"strategy": "cookie",
|
|
14870
|
+
"browser": true,
|
|
14871
|
+
"args": [
|
|
14872
|
+
{
|
|
14873
|
+
"name": "url",
|
|
14874
|
+
"type": "string",
|
|
14875
|
+
"required": true,
|
|
14876
|
+
"positional": true,
|
|
14877
|
+
"help": "Post URL (e.g. https://www.facebook.com/<user>/posts/<id> or a permalink)"
|
|
14878
|
+
},
|
|
14879
|
+
{
|
|
14880
|
+
"name": "remove",
|
|
14881
|
+
"type": "bool",
|
|
14882
|
+
"default": false,
|
|
14883
|
+
"required": false,
|
|
14884
|
+
"help": "Remove your like instead (end in the un-liked state)"
|
|
14885
|
+
}
|
|
14886
|
+
],
|
|
14887
|
+
"columns": [
|
|
14888
|
+
"status",
|
|
14889
|
+
"action",
|
|
14890
|
+
"url",
|
|
14891
|
+
"message"
|
|
14892
|
+
],
|
|
14893
|
+
"type": "js",
|
|
14894
|
+
"modulePath": "facebook/like.js",
|
|
14895
|
+
"sourceFile": "facebook/like.js",
|
|
14896
|
+
"navigateBefore": "https://facebook.com"
|
|
14897
|
+
},
|
|
14829
14898
|
{
|
|
14830
14899
|
"site": "facebook",
|
|
14831
14900
|
"name": "login",
|
|
@@ -17330,6 +17399,42 @@
|
|
|
17330
17399
|
"modulePath": "hackernews/best.js",
|
|
17331
17400
|
"sourceFile": "hackernews/best.js"
|
|
17332
17401
|
},
|
|
17402
|
+
{
|
|
17403
|
+
"site": "hackernews",
|
|
17404
|
+
"name": "comment",
|
|
17405
|
+
"description": "Post a comment on a Hacker News item. Pass the parent id (a story to comment on it, or a comment to reply). Contribute a substantive, on-topic comment — HN flags low-effort or off-topic replies.",
|
|
17406
|
+
"access": "write",
|
|
17407
|
+
"domain": "news.ycombinator.com",
|
|
17408
|
+
"strategy": "cookie",
|
|
17409
|
+
"browser": true,
|
|
17410
|
+
"args": [
|
|
17411
|
+
{
|
|
17412
|
+
"name": "parent",
|
|
17413
|
+
"type": "string",
|
|
17414
|
+
"required": true,
|
|
17415
|
+
"positional": true,
|
|
17416
|
+
"help": "Parent item id (story or comment) to reply to"
|
|
17417
|
+
},
|
|
17418
|
+
{
|
|
17419
|
+
"name": "text",
|
|
17420
|
+
"type": "string",
|
|
17421
|
+
"required": true,
|
|
17422
|
+
"positional": true,
|
|
17423
|
+
"help": "Comment text (HN markup: blank line = paragraph)"
|
|
17424
|
+
}
|
|
17425
|
+
],
|
|
17426
|
+
"columns": [
|
|
17427
|
+
"status",
|
|
17428
|
+
"id",
|
|
17429
|
+
"url",
|
|
17430
|
+
"parent",
|
|
17431
|
+
"message"
|
|
17432
|
+
],
|
|
17433
|
+
"type": "js",
|
|
17434
|
+
"modulePath": "hackernews/comment.js",
|
|
17435
|
+
"sourceFile": "hackernews/comment.js",
|
|
17436
|
+
"navigateBefore": "https://news.ycombinator.com"
|
|
17437
|
+
},
|
|
17333
17438
|
{
|
|
17334
17439
|
"site": "hackernews",
|
|
17335
17440
|
"name": "jobs",
|
|
@@ -17552,6 +17657,47 @@
|
|
|
17552
17657
|
"modulePath": "hackernews/show.js",
|
|
17553
17658
|
"sourceFile": "hackernews/show.js"
|
|
17554
17659
|
},
|
|
17660
|
+
{
|
|
17661
|
+
"site": "hackernews",
|
|
17662
|
+
"name": "submit",
|
|
17663
|
+
"description": "Submit a story to Hacker News. Link post by default (--url), or an Ask/text post with --text. HN gates submissions on account age/karma and dedupes URLs — rejections are surfaced verbatim. Post genuinely worthwhile content; low-effort submissions hurt the account.",
|
|
17664
|
+
"access": "write",
|
|
17665
|
+
"domain": "news.ycombinator.com",
|
|
17666
|
+
"strategy": "cookie",
|
|
17667
|
+
"browser": true,
|
|
17668
|
+
"args": [
|
|
17669
|
+
{
|
|
17670
|
+
"name": "title",
|
|
17671
|
+
"type": "string",
|
|
17672
|
+
"required": true,
|
|
17673
|
+
"positional": true,
|
|
17674
|
+
"help": "Story title (max 80 chars)"
|
|
17675
|
+
},
|
|
17676
|
+
{
|
|
17677
|
+
"name": "url",
|
|
17678
|
+
"type": "string",
|
|
17679
|
+
"required": false,
|
|
17680
|
+
"help": "External URL for a link post (mutually exclusive with --text)"
|
|
17681
|
+
},
|
|
17682
|
+
{
|
|
17683
|
+
"name": "text",
|
|
17684
|
+
"type": "string",
|
|
17685
|
+
"required": false,
|
|
17686
|
+
"help": "Body text for an Ask HN / text post (mutually exclusive with --url)"
|
|
17687
|
+
}
|
|
17688
|
+
],
|
|
17689
|
+
"columns": [
|
|
17690
|
+
"status",
|
|
17691
|
+
"id",
|
|
17692
|
+
"url",
|
|
17693
|
+
"title",
|
|
17694
|
+
"message"
|
|
17695
|
+
],
|
|
17696
|
+
"type": "js",
|
|
17697
|
+
"modulePath": "hackernews/submit.js",
|
|
17698
|
+
"sourceFile": "hackernews/submit.js",
|
|
17699
|
+
"navigateBefore": "https://news.ycombinator.com"
|
|
17700
|
+
},
|
|
17555
17701
|
{
|
|
17556
17702
|
"site": "hackernews",
|
|
17557
17703
|
"name": "top",
|
|
@@ -20751,31 +20897,26 @@
|
|
|
20751
20897
|
"positional": true,
|
|
20752
20898
|
"help": "图片描述 prompt"
|
|
20753
20899
|
},
|
|
20754
|
-
{
|
|
20755
|
-
"name": "model",
|
|
20756
|
-
"type": "string",
|
|
20757
|
-
"default": "high_aes_general_v50",
|
|
20758
|
-
"required": false,
|
|
20759
|
-
"help": "模型: high_aes_general_v50 (5.0 Lite), high_aes_general_v42 (4.6), high_aes_general_v40 (4.0)"
|
|
20760
|
-
},
|
|
20761
20900
|
{
|
|
20762
20901
|
"name": "wait",
|
|
20763
20902
|
"type": "int",
|
|
20764
|
-
"default":
|
|
20903
|
+
"default": 60,
|
|
20765
20904
|
"required": false,
|
|
20766
|
-
"help": "
|
|
20905
|
+
"help": "等待生成完成的最长秒数(每 3 秒轮询一次,超时会返回 pending 并提示用 history 回查)"
|
|
20767
20906
|
}
|
|
20768
20907
|
],
|
|
20769
20908
|
"columns": [
|
|
20770
20909
|
"status",
|
|
20771
20910
|
"prompt",
|
|
20911
|
+
"model",
|
|
20772
20912
|
"image_count",
|
|
20773
20913
|
"image_urls"
|
|
20774
20914
|
],
|
|
20775
20915
|
"type": "js",
|
|
20776
20916
|
"modulePath": "jimeng/generate.js",
|
|
20777
20917
|
"sourceFile": "jimeng/generate.js",
|
|
20778
|
-
"navigateBefore":
|
|
20918
|
+
"navigateBefore": false,
|
|
20919
|
+
"siteSession": "persistent"
|
|
20779
20920
|
},
|
|
20780
20921
|
{
|
|
20781
20922
|
"site": "jimeng",
|
package/clis/dianping/auth.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import{AuthRequiredError as
|
|
1
|
+
import{AuthRequiredError as F,CommandExecutionError as K}from"@jackwener/opencli/errors";import{registerSiteAuthCommands as L}from"../_shared/site-auth.js";async function H(z){return(await z.getCookies({url:"https://www.dianping.com"})).some((B)=>B.name==="dper"&&B.value)}async function J(z){if(!await H(z))throw new F("dianping.com","Dianping dper cookie missing");await z.goto("https://www.dianping.com/citylist");await z.wait(2);const G=await z.evaluate("location.href");if(/account\.dianping\.com\/(pc)?login/.test(String(G||"")))throw new F("dianping.com",`Dianping page redirected to login: ${G}`);const B=await z.evaluate(`
|
|
2
2
|
(() => {
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
return { user_id: uidMatch?.[1] || '', nickname };
|
|
3
|
+
const trigger = document.querySelector('.userinfo-container .J-user-trigger, .userinfo-container a.username');
|
|
4
|
+
if (!trigger) return { loggedOut: true };
|
|
5
|
+
const nickname = (trigger.textContent || '').trim();
|
|
6
|
+
const href = trigger.getAttribute('href') || '';
|
|
7
|
+
const uid = (String(href).match(/\\/member\\/(\\d+)/) || [])[1] || '';
|
|
8
|
+
return { user_id: uid, nickname };
|
|
10
9
|
})()
|
|
11
|
-
`);if(
|
|
10
|
+
`);if(B?.loggedOut)throw new F("dianping.com","Dianping session anonymous — no logged-in user trigger in top nav");if(!B?.user_id)throw new K("Dianping user trigger found but no /member/<id> href — layout drift");return{user_id:String(B.user_id),nickname:String(B.nickname||"")}}L({site:"dianping",domain:"dianping.com",loginUrl:"https://account.dianping.com/pclogin",columns:["user_id","nickname"],quickCheck:H,verify:J,poll:async(z)=>{if(!await H(z))throw new F("dianping.com","Waiting for Dianping dper cookie");return J(z)}});
|
|
@@ -1 +1,4 @@
|
|
|
1
|
-
import{ArgumentError as
|
|
1
|
+
import{ArgumentError as B,CommandExecutionError as J}from"@jackwener/opencli/errors";import{CITY_ID as b,resolveCityId as j}from"./utils.js";const $=/^[一-龥]+$/,F=/^[a-z]+$/,Z=new Map;export function clearCityResolverCache(){Z.clear()}export async function resolveCityIdAsync(z,G){if(G==null||G==="")return null;const q=String(G).trim();if(!q)return null;if(/^\d+$/.test(q))return Number(q);const W=q.toLowerCase();try{const Q=j(q);if(Q!=null)return Q}catch(Q){if(Q?.code!=="ARGUMENT")throw Q}if(Z.has(W))return Z.get(W);if(Z.has(q))return Z.get(q);let K=null;if(F.test(W))K=W;else if($.test(q)){K=await T(z,q);if(!K){const Q=Object.keys(b).filter((X)=>/^[a-z]+$/.test(X)).join(", ");throw new B("city",`unknown city '${G}'. pass a numeric cityId, a pinyin slug (e.g. shantou), a Chinese name listed on dianping.com/citylist, or one of: ${Q}`)}}else{const Q=Object.keys(b).filter((X)=>/^[a-z]+$/.test(X)).join(", ");throw new B("city",`unknown city '${G}'. pass a numeric cityId, a pinyin slug (e.g. shantou), a Chinese name listed on dianping.com/citylist, or one of: ${Q}`)}const U=await v(z,K);if(!U)throw new J(`dianping could not resolve cityId for '${G}' (pinyin=${K}); the city page rendered without a /search/keyword/{id}/ link`);Z.set(W,U);Z.set(K,U);if($.test(q))Z.set(q,U);return U}export async function resolveDefaultCityId(z){await z.goto("https://www.dianping.com/");await z.wait(1);const G=await z.evaluate(`(() => {
|
|
2
|
+
const el = document.querySelector('.city-select-text, .city-select-content');
|
|
3
|
+
return el ? (el.textContent || '').trim() : '';
|
|
4
|
+
})()`);if(!G||!$.test(G))return null;return resolveCityIdAsync(z,G)}async function T(z,G){await z.goto("https://www.dianping.com/citylist");const q=await z.evaluate(`(${buildCitylistMap.toString()})()`);if(!q||typeof q!=="object"||Object.keys(q).length===0)throw new J("dianping citylist did not render any city anchors; cannot resolve Chinese city names");if(q&&typeof q==="object"&&q[G])return String(q[G]).toLowerCase();return null}export function buildCitylistMap(){const z={};document.querySelectorAll("a").forEach((q)=>{const W=q.getAttribute("href")||"",K=(q.textContent||"").trim();if(!K||!/^[一-龥]+$/.test(K))return;const U=W.replace(/^https?:/,""),Q=U.match(/^\/\/(?:www\.)?dianping\.com\/([a-z]+)\/?$/)||U.match(/^\/([a-z]+)\/?$/);if(!Q)return;const X=Q[1].toLowerCase();if(X==="citylist"||X==="promo"||X==="events")return;if(!z[K])z[K]=X});return z}async function v(z,G){await z.goto(`https://www.dianping.com/${G}`);const q=await z.evaluate(`(${extractCityIdFromPage.toString()})()`);return Number.isInteger(q)&&q>0?q:null}export function extractCityIdFromPage(){const z=typeof location<"u"&&location.href||"https://www.dianping.com/",G=document.querySelectorAll("a[href]");for(const q of G){const W=q.getAttribute("href")||"";let K;try{K=new URL(W,z)}catch{continue}if(K.protocol!=="https:")continue;if(K.hostname!=="www.dianping.com"&&K.hostname!=="dianping.com")continue;const U=K.pathname.match(/^\/search\/keyword\/(\d+)(?:\/|$)/);if(!U)continue;const Q=Number(U[1]);if(Number.isInteger(Q)&&Q>0)return Q}return null}
|
package/clis/dianping/search.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{cli as
|
|
1
|
+
import{cli as L,Strategy as O}from"@jackwener/opencli/registry";import{ArgumentError as W,CommandExecutionError as F}from"@jackwener/opencli/errors";import{SEARCH_COLUMNS as b,detectAuthOrPageFailure as P,parsePrice as j,parseReviewCount as x,requireSearchLimit as f,wrapDianpingStep as $}from"./utils.js";import{resolveCityIdAsync as D,resolveDefaultCityId as A}from"./cityResolver.js";export function extractSearchRows(){const J=document.querySelectorAll("#shop-all-list li");if(J.length===0){const z=document.body;return{ok:!1,sample:(z&&(z.innerText||z.textContent)||"").slice(0,800),url:location.href}}const Q=[];J.forEach((z,Z)=>{if(!(z.querySelector(".tit h4, .review-num, .mean-price, .tag-addr")||z.querySelector('.tit a, a[data-shopid], a[href*="/shop/"]')))return;const K=z.querySelector('.tit a[href*="/shop/"]')||z.querySelector("a[data-shopid]")||z.querySelector('a[href*="/shop/"]'),T=K&&K.getAttribute("data-shopid")||K&&(K.getAttribute("href")||"").match(/\/shop\/([^?#/]+)/)?.[1]||"",G=z.querySelector(".tit h4"),Y=G&&G.textContent&&G.textContent.trim()||K&&K.getAttribute("title")||"",B=z.querySelector(".review-num b"),U=B&&B.textContent&&B.textContent.trim()||"",q=z.querySelector(".mean-price b"),_=q&&q.textContent&&q.textContent.trim()||"",H=Array.from(z.querySelectorAll(".tag-addr .tag")).map((V)=>V.textContent.trim()).filter(Boolean);let M="";const N=z.querySelector(".nebula_star");if(N){const V=N.outerHTML.match(/star_(\d{2})/g);if(V&&V.length)M=V[V.length-1].match(/star_(\d{2})/)[1]}Q.push({rank:Z+1,shop_id:T,name:Y,starClass:M,reviewsRaw:U,priceRaw:_,cuisine:H[0]||"",district:H[1]||"",url:T?"https://www.dianping.com/shop/"+T:""})});return{ok:!0,rows:Q}}L({site:"dianping",name:"search",access:"read",description:"大众点评店铺搜索(按关键词 + 城市)",domain:"www.dianping.com",strategy:O.COOKIE,args:[{name:"keyword",required:!0,positional:!0,help:'搜索关键词,例如 "火锅"'},{name:"city",help:"城市名(北京/上海/汕头/beijing/shantou/...)或 cityId 数字。未在静态表中的城市会通过 dianping.com 在线解析。不传则使用 cookie 默认城市"},{name:"limit",type:"int",default:15,help:"返回的店铺数量(最多 15,dianping 单页固定 15 条)"}],columns:b,func:async(J,Q)=>{const z=String(Q.keyword||"").trim();if(!z)throw new W("keyword","must be a non-empty string");const Z=f(Q.limit);let X=await $("city resolve",()=>D(J,Q.city));if(X==null)X=await $("default city resolve",()=>A(J));if(X==null)throw new F("dianping search 需要城市:未传 --city 且无法确定默认城市。请显式指定,例如 --city 上海");const T=`https://www.dianping.com${`/search/keyword/${X}/0_${encodeURIComponent(z)}`}`;await $(`search "${z}" navigation`,async()=>{await J.goto(T);await J.wait(2)});const G=await $(`search "${z}" extraction`,()=>J.evaluate(`(${extractSearchRows.toString()})()`));if(!G||!G.ok)P({text:String(G?.sample||""),url:String(G?.url||T)},`search "${z}"`,{emptyPatterns:[/没有找到|暂无结果|暂无商户|换个关键词|未找到相关/i]});const Y=(G.rows||[]).slice(0,Z);if(Y.length===0)throw new F("dianping search parser found no result-shaped shop cards");if(Y.some((B)=>!B?.shop_id))throw new F("dianping search parser found result cards without shop_id values");return Y.map((B)=>({rank:B.rank,shop_id:B.shop_id,name:B.name,rating:B.starClass?Number((Number(B.starClass)/10).toFixed(1)):null,reviews:x(B.reviewsRaw),price:j(B.priceRaw),cuisine:B.cuisine,district:B.district,url:B.url}))}});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import{ArgumentError as H,AuthRequiredError as Z,CommandExecutionError as J}from"@jackwener/opencli/errors";import{cli as _,Strategy as $}from"@jackwener/opencli/registry";const Y='[data-lexical-editor="true"][contenteditable="true"]',K='[data-pp-fb-composer="1"]';_({site:"facebook",name:"comment",access:"write",description:"Post a comment on a Facebook post. Pass the post URL and the comment text (multi-line allowed). The comment is published from your logged-in account — write a genuine, on-topic remark, not filler.",domain:"facebook.com",strategy:$.COOKIE,browser:!0,args:[{name:"url",type:"string",required:!0,positional:!0,help:"Post URL (e.g. https://www.facebook.com/<user>/posts/<id> or a permalink)"},{name:"text",type:"string",required:!0,positional:!0,help:"Comment text (multi-line allowed)"}],columns:["status","url","message"],func:async(v,U)=>{if(!v)throw new J("Browser session required");const B=String(U.url??"").trim();if(!B)throw new H("Post URL is required.");let L;try{L=new URL(B)}catch{throw new H(`Invalid post URL: ${B}`)}if(!/facebook\.com$/.test(L.hostname)&&!L.hostname.endsWith(".facebook.com"))throw new H("URL must be a facebook.com post URL.");const G=String(U.text??"");if(!G.trim())throw new H("Comment text cannot be empty.");await v.goto(B,{waitUntil:"none"});let V=!1;for(let z=0;z<15;z++){const X=await v.evaluate(`(() => {
|
|
2
|
+
const path = location.pathname || '';
|
|
3
|
+
if (/^\\/(login|checkpoint)(\\/|$|\\.php)/.test(path)) return 'login';
|
|
4
|
+
const dialog = document.querySelector('[role="dialog"]');
|
|
5
|
+
const scope = dialog || document;
|
|
6
|
+
const ed = scope.querySelector('${Y}') || document.querySelector('${Y}');
|
|
7
|
+
if (!ed) return 'wait';
|
|
8
|
+
ed.setAttribute('data-pp-fb-composer', '1');
|
|
9
|
+
ed.scrollIntoView({ block: 'center' });
|
|
10
|
+
return 'ready';
|
|
11
|
+
})()`);if(X==="login")throw new Z("www.facebook.com","Facebook redirected to login/checkpoint — not signed in");if(X==="ready"){V=!0;break}await v.wait(1)}if(!V)throw new J("Comment box not found — the post may be unavailable, or commenting is disabled.");await v.click(K);await v.wait(1);await v.pressKey("Control+A");await v.pressKey("Delete");const N=G.split(`
|
|
12
|
+
`);for(let z=0;z<N.length;z++){if(z>0)await v.pressKey("Shift+Enter");if(N[z].length)await v.typeText(K,N[z])}if(await v.evaluate(`(() => !!document.querySelector('[role="listbox"][aria-label], ul[role="listbox"]'))()`))await v.pressKey("Escape");const F=(z)=>String(z||"").replace(/\s+/g," ").trim(),Q=await v.evaluate(`(() => {
|
|
13
|
+
const ed = document.querySelector('${K}');
|
|
14
|
+
return ed ? (ed.textContent || '') : null;
|
|
15
|
+
})()`);if(Q===null||F(Q)!==F(G))throw new J(`Composed text did not match before send (got ${JSON.stringify((Q||"").slice(0,60))}).`);await v.pressKey("Enter");await v.wait(2);const W=await v.evaluate(`(() => {
|
|
16
|
+
const ed = document.querySelector('${K}');
|
|
17
|
+
return ed ? (ed.textContent || '') : '';
|
|
18
|
+
})()`);if(F(W).length>0&&F(W)===F(G))throw new J("Comment still in the box after Enter — submit blocked (rate limit, restricted post, or no permission to comment).");return[{status:"success",url:B,message:"Comment posted."}]}});
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import{ArgumentError as Z,AuthRequiredError as y,CommandExecutionError as V}from"@jackwener/opencli/errors";import{cli as N,Strategy as R}from"@jackwener/opencli/registry";const $="data-pp-fb-like";function U(){return`(() => {
|
|
2
|
+
const path = location.pathname || '';
|
|
3
|
+
if (/^\\/(login|checkpoint)(\\/|$|\\.php)/.test(path)) return { auth: true, detail: 'on login/checkpoint page' };
|
|
4
|
+
// A permalink often renders as a modal dialog over the feed. Scope to the
|
|
5
|
+
// dialog so we don't grab a background feed post's Like button.
|
|
6
|
+
const dialog = document.querySelector('[role="dialog"]');
|
|
7
|
+
const art = (dialog && dialog.querySelector('div[role="article"]'))
|
|
8
|
+
|| dialog
|
|
9
|
+
|| document.querySelector('div[role="article"]');
|
|
10
|
+
if (!art) return { notfound: true, detail: 'no post found on page' };
|
|
11
|
+
// Action buttons = focusable role=button carrying a css-img icon, not part
|
|
12
|
+
// of the reaction-count toolbar. The first one is Like.
|
|
13
|
+
const btns = [...art.querySelectorAll('[role="button"][tabindex="0"]')]
|
|
14
|
+
.filter(b => !b.closest('[role="toolbar"]') && b.querySelector('i[data-visualcompletion="css-img"]'));
|
|
15
|
+
const like = btns[0];
|
|
16
|
+
if (!like) return { notfound: true, detail: 'like button not located' };
|
|
17
|
+
like.setAttribute(${JSON.stringify($)}, '1');
|
|
18
|
+
like.scrollIntoView({ block: 'center' });
|
|
19
|
+
const icon = like.querySelector('i[data-visualcompletion="css-img"]');
|
|
20
|
+
const y = parseFloat((getComputedStyle(icon).backgroundPosition.split(' ')[1] || '0').replace('px','')) || 0;
|
|
21
|
+
return { y, label: like.getAttribute('aria-label') || '' };
|
|
22
|
+
})()`}function G(){return`(() => {
|
|
23
|
+
const like = document.querySelector('[${$}="1"]');
|
|
24
|
+
if (!like) return null;
|
|
25
|
+
const icon = like.querySelector('i[data-visualcompletion="css-img"]');
|
|
26
|
+
if (!icon) return null;
|
|
27
|
+
const y = parseFloat((getComputedStyle(icon).backgroundPosition.split(' ')[1] || '0').replace('px','')) || 0;
|
|
28
|
+
return { y, label: like.getAttribute('aria-label') || '' };
|
|
29
|
+
})()`}async function v(z,O,H){for(let J=0;J<H;J++){await z.click(`[${$}="1"]`);await z.wait(1);const M=await z.evaluate(G());if(M&&M.y!==O)return M}return null}N({site:"facebook",name:"like",access:"write",description:"Like a Facebook post (ends in the liked state; no-op if already liked). Pass the post URL. Reacts as a genuine like from your logged-in account — use it to engage with content you actually mean to endorse.",domain:"facebook.com",strategy:R.COOKIE,browser:!0,args:[{name:"url",type:"string",required:!0,positional:!0,help:"Post URL (e.g. https://www.facebook.com/<user>/posts/<id> or a permalink)"},{name:"remove",type:"bool",default:!1,help:"Remove your like instead (end in the un-liked state)"}],columns:["status","action","url","message"],func:async(z,O)=>{if(!z)throw new V("Browser session required");const H=String(O.url??"").trim();if(!H)throw new Z("Post URL is required.");let J;try{J=new URL(H)}catch{throw new Z(`Invalid post URL: ${H}`)}if(!/facebook\.com$/.test(J.hostname)&&!J.hostname.endsWith(".facebook.com"))throw new Z("URL must be a facebook.com post URL.");const M=O.remove===!0;await z.goto(H,{waitUntil:"none"});let B=null;for(let X=0;X<15;X++){await z.wait(1);B=await z.evaluate(U());if(B?.auth)throw new y("www.facebook.com",`Facebook ${B.detail} — not signed in`);if(typeof B?.y==="number")break}if(typeof B?.y!=="number")throw new V(`Could not act on this post: ${B?.detail||"like button never appeared"}.`);const P=await v(z,B.y,5);if(!P)throw new V("Like did not register — Facebook ignored the click (post may be unavailable or reactions disabled).");const q=Math.max(B.y,P.y),D=P.y===q,j=B.y===q,W=!M;let Q;if(D===W)Q=W?j?"already-liked":"liked":"unliked";else{if(!await v(z,P.y,3))throw new V("Could not settle the reaction to the desired state (second toggle ignored).");Q=W?"already-liked":"already-unliked"}return[{status:"success",action:Q,url:H,message:{liked:"Post liked.","already-liked":"Post was already liked (left liked).",unliked:"Like removed.","already-unliked":"Post was not liked (left un-liked)."}[Q]||"Reaction updated."}]}});
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import{ArgumentError as Q,AuthRequiredError as T,CommandExecutionError as L}from"@jackwener/opencli/errors";import{cli as U,Strategy as V}from"@jackwener/opencli/registry";const M="https://news.ycombinator.com";export function normalizeItemId(F){const J=String(F||"").trim();if(!J)throw new Q("Item id is required.","Pass an HN item id (story or comment), e.g. 48811591.");if(/^\d+$/.test(J))return J;const B=J.match(/[?&]id=(\d+)/);if(B)return B[1];throw new Q(`Invalid HN item reference: ${JSON.stringify(J)}`,"Pass a numeric id or an item?id=… URL.")}U({site:"hackernews",name:"comment",access:"write",description:"Post a comment on a Hacker News item. Pass the parent id (a story to comment on it, or a comment to reply). Contribute a substantive, on-topic comment — HN flags low-effort or off-topic replies.",domain:"news.ycombinator.com",strategy:V.COOKIE,browser:!0,args:[{name:"parent",type:"string",required:!0,positional:!0,help:"Parent item id (story or comment) to reply to"},{name:"text",type:"string",required:!0,positional:!0,help:"Comment text (HN markup: blank line = paragraph)"}],columns:["status","id","url","parent","message"],func:async(F,J)=>{if(!F)throw new L("Browser session required");const B=normalizeItemId(J.parent),P=String(J.text??"");if(!P.trim())throw new Q("Comment text cannot be empty.");await F.goto(`${M}/item?id=${B}`);await F.wait(1);const D=await F.evaluate(`(async () => {
|
|
2
|
+
try {
|
|
3
|
+
if (/\\/login/.test(location.pathname)) return { kind: 'auth', detail: 'redirected to /login' };
|
|
4
|
+
// The reply form posts to "comment" (relative). Match it by the hidden
|
|
5
|
+
// fields it carries rather than the action attribute, which HN writes
|
|
6
|
+
// relative ("comment") so /comment suffix selectors miss it.
|
|
7
|
+
const forms = [...document.querySelectorAll('form')].filter(f => f.querySelector('input[name="hmac"]') && f.querySelector('input[name="parent"]'));
|
|
8
|
+
const form = forms.find(f => (f.querySelector('input[name="parent"]')?.value) === ${JSON.stringify(B)}) || forms[0];
|
|
9
|
+
if (!form) return { kind: 'notfound', detail: 'No comment form on this item — it may be closed, deleted, or you are signed out.' };
|
|
10
|
+
const hmac = form.querySelector('input[name="hmac"]')?.value;
|
|
11
|
+
const goto = form.querySelector('input[name="goto"]')?.value || ('item?id=' + ${JSON.stringify(B)});
|
|
12
|
+
const parentVal = form.querySelector('input[name="parent"]')?.value || ${JSON.stringify(B)};
|
|
13
|
+
if (!hmac) return { kind: 'auth', detail: 'comment hmac token missing — likely signed out' };
|
|
14
|
+
|
|
15
|
+
const p = new URLSearchParams();
|
|
16
|
+
p.set('parent', parentVal);
|
|
17
|
+
p.set('goto', goto);
|
|
18
|
+
p.set('hmac', hmac);
|
|
19
|
+
p.set('text', ${JSON.stringify(P)});
|
|
20
|
+
|
|
21
|
+
const res = await fetch('/comment', {
|
|
22
|
+
method: 'POST',
|
|
23
|
+
credentials: 'include',
|
|
24
|
+
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
|
25
|
+
body: p.toString(),
|
|
26
|
+
redirect: 'manual',
|
|
27
|
+
});
|
|
28
|
+
if (res.type === 'opaqueredirect' || res.status === 302 || res.status === 0) {
|
|
29
|
+
return { ok: true };
|
|
30
|
+
}
|
|
31
|
+
const body = await res.text();
|
|
32
|
+
let msg = '';
|
|
33
|
+
if (/Please try again/i.test(body)) msg = 'HN asked to try again (possible rate limit or expired token).';
|
|
34
|
+
else if (/You're posting too fast|too fast/i.test(body)) msg = 'Posting too fast — HN rate limited the comment.';
|
|
35
|
+
else {
|
|
36
|
+
const td = body.match(/<td[^>]*>\\s*([^<][^<]{0,200}?)\\s*<\\/td>/i);
|
|
37
|
+
if (td) msg = td[1].replace(/\\s+/g, ' ').trim();
|
|
38
|
+
}
|
|
39
|
+
return { kind: 'reject', detail: msg || ('HTTP ' + res.status + ' without redirect'), status: res.status };
|
|
40
|
+
} catch (e) {
|
|
41
|
+
return { kind: 'exception', detail: String((e && e.message) || e) };
|
|
42
|
+
}
|
|
43
|
+
})()`);if(D?.kind==="auth")throw new T("news.ycombinator.com",D.detail);if(D?.kind==="notfound")throw new L(D.detail);if(D?.kind==="exception")throw new L(`HN comment failed: ${D.detail}`);if(D?.kind==="reject")return[{status:"failed",id:"",url:"",parent:B,message:D.detail}];if(!D?.ok)throw new L(`Unexpected HN comment result: ${JSON.stringify(D)}`);await F.goto(`${M}/item?id=${B}`);await F.wait(1);const K=(await F.evaluate(`(() => {
|
|
44
|
+
try {
|
|
45
|
+
let username = '';
|
|
46
|
+
const navLink = document.querySelector('span.pagetop a[href^="user?id="]');
|
|
47
|
+
if (navLink) username = (navLink.getAttribute('href') || '').replace('user?id=', '');
|
|
48
|
+
const want = ${JSON.stringify(P)}.replace(/\\s+/g, ' ').trim();
|
|
49
|
+
const rows = [...document.querySelectorAll('tr.athing.comtr')];
|
|
50
|
+
// Newest first: our fresh comment is usually near the top of its thread.
|
|
51
|
+
for (const row of rows) {
|
|
52
|
+
const by = (row.querySelector('a.hnuser')?.textContent || '').trim();
|
|
53
|
+
if (username && by !== username) continue;
|
|
54
|
+
const commentText = (row.querySelector('.commtext')?.textContent || '').replace(/\\s+/g, ' ').trim();
|
|
55
|
+
if (commentText.startsWith(want.slice(0, 60))) {
|
|
56
|
+
return { id: row.id };
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return null;
|
|
60
|
+
} catch { return null; }
|
|
61
|
+
})()`))?.id||"";return[{status:"success",id:K,url:K?`${M}/item?id=${K}`:`${M}/item?id=${B}`,parent:B,message:K?"Comment posted":"Comment posted (id not confirmed on reload)"}]}});
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import{ArgumentError as F,AuthRequiredError as Q,CommandExecutionError as L}from"@jackwener/opencli/errors";import{cli as T,Strategy as V}from"@jackwener/opencli/registry";const M="https://news.ycombinator.com";T({site:"hackernews",name:"submit",access:"write",description:"Submit a story to Hacker News. Link post by default (--url), or an Ask/text post with --text. HN gates submissions on account age/karma and dedupes URLs — rejections are surfaced verbatim. Post genuinely worthwhile content; low-effort submissions hurt the account.",domain:"news.ycombinator.com",strategy:V.COOKIE,browser:!0,args:[{name:"title",type:"string",required:!0,positional:!0,help:"Story title (max 80 chars)"},{name:"url",type:"string",help:"External URL for a link post (mutually exclusive with --text)"},{name:"text",type:"string",help:"Body text for an Ask HN / text post (mutually exclusive with --url)"}],columns:["status","id","url","title","message"],func:async(v,D)=>{if(!v)throw new L("Browser session required");const z=String(D.title??"").trim();if(!z)throw new F("Title is required.");if(z.length>80)throw new F("HN titles must be at most 80 characters.");const B=typeof D.url==="string"?D.url.trim():"",K=typeof D.text==="string"?D.text:"";if(B&&K)throw new F("Pass either --url (link post) or --text (text post), not both.");if(!B&&!K)throw new F("A story needs either --url or --text.","Give a link to submit, or --text for an Ask HN post.");if(B)try{new URL(B)}catch{throw new F(`Invalid --url: ${B}`)}await v.goto(`${M}/submit`);await v.wait(1);const f=await v.evaluate(`(async () => {
|
|
2
|
+
try {
|
|
3
|
+
// The submit form only renders for a signed-in user; if HN bounced us
|
|
4
|
+
// to /login the form (and its fnid) will be absent.
|
|
5
|
+
if (/\\/login/.test(location.pathname)) return { kind: 'auth', detail: 'redirected to /login' };
|
|
6
|
+
const form = document.querySelector('form[action$="/r"], form[action="/r"], form[action="https://news.ycombinator.com/r"]')
|
|
7
|
+
|| [...document.querySelectorAll('form')].find(f => f.querySelector('input[name="fnid"]'));
|
|
8
|
+
if (!form) return { kind: 'auth', detail: 'submit form not found — not signed in' };
|
|
9
|
+
const fnid = form.querySelector('input[name="fnid"]')?.value;
|
|
10
|
+
if (!fnid) return { kind: 'auth', detail: 'fnid token missing' };
|
|
11
|
+
|
|
12
|
+
const p = new URLSearchParams();
|
|
13
|
+
p.set('fnid', fnid);
|
|
14
|
+
p.set('fnop', 'submit-page');
|
|
15
|
+
p.set('title', ${JSON.stringify(z)});
|
|
16
|
+
p.set('url', ${JSON.stringify(B)});
|
|
17
|
+
p.set('text', ${JSON.stringify(K)});
|
|
18
|
+
|
|
19
|
+
const res = await fetch('/r', {
|
|
20
|
+
method: 'POST',
|
|
21
|
+
credentials: 'include',
|
|
22
|
+
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
|
23
|
+
body: p.toString(),
|
|
24
|
+
redirect: 'manual',
|
|
25
|
+
});
|
|
26
|
+
// A same-origin 302 comes back as an opaque redirect (status 0) — that
|
|
27
|
+
// is the success path. A 200 means HN re-rendered the form with an error.
|
|
28
|
+
if (res.type === 'opaqueredirect' || res.status === 302 || res.status === 0) {
|
|
29
|
+
return { ok: true };
|
|
30
|
+
}
|
|
31
|
+
const body = await res.text();
|
|
32
|
+
// Pull the first human-readable error HN prints above the form.
|
|
33
|
+
let msg = '';
|
|
34
|
+
const td = body.match(/<td[^>]*>\\s*([^<][^<]{0,200}?)\\s*<\\/td>/i);
|
|
35
|
+
if (/Please try again/i.test(body)) msg = 'HN asked to try again (possible rate limit or expired token).';
|
|
36
|
+
else if (/already been submitted/i.test(body)) msg = 'That URL has already been submitted.';
|
|
37
|
+
else if (td) msg = td[1].replace(/\\s+/g, ' ').trim();
|
|
38
|
+
return { kind: 'reject', detail: msg || ('HTTP ' + res.status + ' without redirect'), status: res.status };
|
|
39
|
+
} catch (e) {
|
|
40
|
+
return { kind: 'exception', detail: String((e && e.message) || e) };
|
|
41
|
+
}
|
|
42
|
+
})()`);if(f?.kind==="auth")throw new Q("news.ycombinator.com",f.detail);if(f?.kind==="exception")throw new L(`HN submit failed: ${f.detail}`);if(f?.kind==="reject")return[{status:"failed",id:"",url:"",title:z,message:f.detail}];if(!f?.ok)throw new L(`Unexpected HN submit result: ${JSON.stringify(f)}`);await v.wait(1);const J=(await v.evaluate(`(async () => {
|
|
43
|
+
try {
|
|
44
|
+
const uc = document.cookie.match(/(?:^|; )user=([^;]+)/);
|
|
45
|
+
// Cookie value is "<username>&<hash>"; the nav link is more reliable.
|
|
46
|
+
let username = '';
|
|
47
|
+
const navLink = document.querySelector('span.pagetop a[href^="user?id="]');
|
|
48
|
+
if (navLink) username = (navLink.getAttribute('href') || '').replace('user?id=', '');
|
|
49
|
+
if (!username && uc) username = decodeURIComponent(uc[1]).split('&')[0];
|
|
50
|
+
if (!username) return null;
|
|
51
|
+
const res = await fetch('/submitted?id=' + encodeURIComponent(username), { credentials: 'include' });
|
|
52
|
+
const html = await res.text();
|
|
53
|
+
const doc = new DOMParser().parseFromString(html, 'text/html');
|
|
54
|
+
const rows = [...doc.querySelectorAll('tr.athing')];
|
|
55
|
+
const want = ${JSON.stringify(z)}.replace(/\\s+/g, ' ').trim();
|
|
56
|
+
for (const row of rows.slice(0, 5)) {
|
|
57
|
+
const link = row.querySelector('.titleline a, a.storylink, .title a');
|
|
58
|
+
const t = (link?.textContent || '').replace(/\\s+/g, ' ').trim();
|
|
59
|
+
if (t === want) {
|
|
60
|
+
return { id: row.id, href: link?.getAttribute('href') || '' };
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return { id: rows[0]?.id || '', href: '' };
|
|
64
|
+
} catch { return null; }
|
|
65
|
+
})()`))?.id||"",P=J?`${M}/item?id=${J}`:"";return[{status:"success",id:J,url:P,title:z,message:J?"Story submitted":"Story submitted (item id not confirmed; check /newest)"}]}});
|
package/clis/jimeng/auth.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{AuthRequiredError as
|
|
1
|
+
import{AuthRequiredError as L,CommandExecutionError as F}from"@jackwener/opencli/errors";import{registerSiteAuthCommands as T}from"../_shared/site-auth.js";const Q=`(async () => {
|
|
2
2
|
try {
|
|
3
3
|
const r = await fetch('/passport/account/info/v2/?aid=513695', { credentials: 'include', headers: { Accept: 'application/json' } });
|
|
4
4
|
if (r.status === 401 || r.status === 403) return { kind: 'auth', detail: 'Jimeng passport HTTP ' + r.status };
|
|
@@ -10,4 +10,4 @@ import{AuthRequiredError as G,CommandExecutionError as F}from"@jackwener/opencli
|
|
|
10
10
|
} catch (e) {
|
|
11
11
|
return { kind: 'exception', detail: String(e && e.message || e) };
|
|
12
12
|
}
|
|
13
|
-
})()
|
|
13
|
+
})()`,U=new Set(["sessionid","sessionid_ss","sid_tt"]);async function V(D){return{logged_in:(await D.getCookies({url:"https://jimeng.jianying.com"})).some((G)=>G.value&&U.has(G.name))}}async function X(D){await D.goto("https://jimeng.jianying.com/ai-tool/generate?type=image&workspace=0");await D.wait(2);const z=await D.evaluate(Q);if(z?.kind==="auth")throw new L("jimeng.jianying.com",z.detail);if(z?.kind==="http")throw new F(`HTTP ${z.httpStatus} from Jimeng passport`);if(z?.kind==="exception")throw new F(`Jimeng whoami failed: ${z.detail}`);if(!z?.ok)throw new F(`Unexpected Jimeng probe: ${JSON.stringify(z)}`);return{user_id:z.user_id,screen_name:z.screen_name}}T({site:"jimeng",domain:"jimeng.jianying.com",loginUrl:"https://jimeng.jianying.com/",columns:["user_id","screen_name"],verify:X,quickCheck:V,poll:async(D)=>{const z=await D.evaluate(Q);if(!z?.ok)throw new L("jimeng.jianying.com","Waiting for Jimeng login");return{user_id:z.user_id,screen_name:z.screen_name}}});
|
package/clis/jimeng/generate.js
CHANGED
|
@@ -1,53 +1,60 @@
|
|
|
1
|
-
import{cli as
|
|
2
|
-
const prompt =
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
import{cli as h,Strategy as G}from"@jackwener/opencli/registry";import{CommandExecutionError as F}from"@jackwener/opencli/errors";const M="https://jimeng.jianying.com/ai-tool/generate?type=image&workspace=0",V="/mweb/v1/get_history?aid=513695&device_platform=web®ion=cn&da_version=3.3.11&web_version=7.5.0&aigc_features=app_lip_sync",W=JSON.stringify({cursor:"",count:5,need_page_item:!0,need_aigc_data:!0,aigc_mode_list:["workbench"]}),N=(q)=>`(async () => {
|
|
2
|
+
const prompt = ${JSON.stringify(q)};
|
|
3
|
+
let existing = [];
|
|
4
|
+
try {
|
|
5
|
+
const r = await fetch(${JSON.stringify(V)}, {
|
|
6
|
+
method: 'POST', credentials: 'include',
|
|
7
|
+
headers: { 'Content-Type': 'application/json' },
|
|
8
|
+
body: ${JSON.stringify(W)},
|
|
9
|
+
});
|
|
10
|
+
const d = await r.json();
|
|
11
|
+
existing = (d && d.data && d.data.records_list || []).map((x) => x.submit_id).filter(Boolean);
|
|
12
|
+
} catch (e) { /* 基线拿不到就当空,轮询取最新一条 */ }
|
|
13
|
+
|
|
14
|
+
const editor = document.querySelector('[contenteditable="true"]');
|
|
15
|
+
if (!editor) return { ok: false, error: 'editor_not_found' };
|
|
13
16
|
editor.focus();
|
|
14
|
-
await new Promise(r => setTimeout(r, 200));
|
|
17
|
+
await new Promise((r) => setTimeout(r, 200));
|
|
15
18
|
document.execCommand('selectAll');
|
|
16
|
-
await new Promise(r => setTimeout(r,
|
|
19
|
+
await new Promise((r) => setTimeout(r, 80));
|
|
17
20
|
document.execCommand('delete');
|
|
18
|
-
await new Promise(r => setTimeout(r,
|
|
21
|
+
await new Promise((r) => setTimeout(r, 150));
|
|
19
22
|
document.execCommand('insertText', false, prompt);
|
|
20
|
-
await new Promise(r => setTimeout(r,
|
|
21
|
-
|
|
22
|
-
// Step 3: Click generate
|
|
23
|
+
await new Promise((r) => setTimeout(r, 400));
|
|
24
|
+
|
|
23
25
|
const btn = document.querySelector('.lv-btn.lv-btn-primary[class*="circle"]');
|
|
24
|
-
if (!btn) return
|
|
26
|
+
if (!btn) return { ok: false, error: 'button_not_found' };
|
|
27
|
+
if (btn.disabled || btn.getAttribute('aria-disabled') === 'true') return { ok: false, error: 'button_disabled' };
|
|
25
28
|
btn.click();
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
29
|
+
return { ok: true, existing };
|
|
30
|
+
})()`,j=(q)=>`(async () => {
|
|
31
|
+
const existing = ${JSON.stringify(q)};
|
|
32
|
+
const r = await fetch(${JSON.stringify(V)}, {
|
|
33
|
+
method: 'POST', credentials: 'include',
|
|
34
|
+
headers: { 'Content-Type': 'application/json' },
|
|
35
|
+
body: ${JSON.stringify(W)},
|
|
36
|
+
});
|
|
37
|
+
const d = await r.json();
|
|
38
|
+
const recs = (d && d.data && d.data.records_list) || [];
|
|
39
|
+
const fresh = recs.find((x) => x.submit_id && existing.indexOf(x.submit_id) === -1);
|
|
40
|
+
if (!fresh) return { state: 'pending' };
|
|
41
|
+
|
|
42
|
+
const failMsg = fresh.fail_starling_message || '';
|
|
43
|
+
const items = fresh.item_list || [];
|
|
44
|
+
const done = items
|
|
45
|
+
.map((it) => it && it.image && it.image.large_images && it.image.large_images[0] && it.image.large_images[0].image_url)
|
|
46
|
+
.filter(Boolean);
|
|
47
|
+
const total = fresh.total_image_count || 0;
|
|
48
|
+
|
|
49
|
+
if (done.length && (!total || done.length >= total)) {
|
|
50
|
+
const p = items[0] && items[0].aigc_image_params && items[0].aigc_image_params.text2image_params;
|
|
51
|
+
return {
|
|
52
|
+
state: 'success',
|
|
53
|
+
urls: done,
|
|
54
|
+
model: (fresh.model_info && fresh.model_info.model_name) || (p && p.model_config && p.model_config.model_name) || '',
|
|
55
|
+
};
|
|
37
56
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
// Step 5: Extract image URLs (use thumbnail URLs which are accessible)
|
|
44
|
-
const urls = newImgs.map(img => img.src);
|
|
45
|
-
|
|
46
|
-
return [{
|
|
47
|
-
status: 'success',
|
|
48
|
-
prompt: prompt.substring(0, 80),
|
|
49
|
-
image_count: urls.length,
|
|
50
|
-
image_urls: urls.join('\\n')
|
|
51
|
-
}];
|
|
52
|
-
})()
|
|
53
|
-
`},{map:{status:"${{ item.status }}",prompt:"${{ item.prompt }}",image_count:"${{ item.image_count }}",image_urls:"${{ item.image_urls }}"}}]});
|
|
57
|
+
if (!done.length && failMsg) return { state: 'failed', error: failMsg };
|
|
58
|
+
return { state: 'pending', got: done.length, total };
|
|
59
|
+
})()`;h({site:"jimeng",name:"generate",access:"write",description:"即梦AI 文生图 — 输入 prompt 生成图片",domain:"jimeng.jianying.com",strategy:G.COOKIE,browser:!0,navigateBefore:!1,siteSession:"persistent",args:[{name:"prompt",type:"string",required:!0,positional:!0,help:"图片描述 prompt"},{name:"wait",type:"int",default:60,help:"等待生成完成的最长秒数(每 3 秒轮询一次,超时会返回 pending 并提示用 history 回查)"}],columns:["status","prompt","model","image_count","image_urls"],func:async(q,K)=>{const z=String(K.prompt??"").trim();if(!z)throw new F("prompt is required");const Q=Number(K.wait??60);await q.goto(M);await q.wait(3);const v=await q.evaluate(N(z));if(!v?.ok){const $={editor_not_found:"找不到 prompt 输入框(页面结构可能已变)",button_not_found:"找不到生成按钮(页面结构可能已变)",button_disabled:"生成按钮不可点击(可能未登录、额度用尽或 prompt 为空)"}[v?.error]||`提交失败:${v?.error||"unknown"}`;throw new F($)}const X=Array.isArray(v.existing)?v.existing:[],Z=Date.now()+Q*1000;let f=null;while(Date.now()<Z){await q.wait(3);f=await q.evaluate(j(X));if(f?.state==="success")return[{status:"success",prompt:z.slice(0,80),model:f.model||"",image_count:f.urls.length,image_urls:f.urls.join(`
|
|
60
|
+
`)}];if(f?.state==="failed")throw new F(`即梦生成失败:${f.error}`)}return[{status:"pending",prompt:z.slice(0,80),model:f&&f.model||"",image_count:f&&f.got||0,image_urls:`生成仍在进行(已 ${Q}s);稍后用 \`opencli jimeng history\` 回查结果`}]}});
|
package/clis/jimeng/history.js
CHANGED
|
@@ -1,23 +1,32 @@
|
|
|
1
1
|
import{cli as e,Strategy as t}from"@jackwener/opencli/registry";e({site:"jimeng",name:"history",access:"read",description:"即梦AI 查看最近生成的作品",domain:"jimeng.jianying.com",strategy:t.COOKIE,browser:!0,args:[{name:"limit",type:"int",default:5}],columns:["prompt","model","status","image_url","created_at"],pipeline:[{navigate:"https://jimeng.jianying.com/ai-tool/generate?type=image&workspace=0"},{evaluate:`(async () => {
|
|
2
2
|
const limit = \${{ args.limit }};
|
|
3
|
+
// get_history 的响应结构已从 history_list 改版为 records_list:每条 record 是一次
|
|
4
|
+
// 生成任务,其 item_list 才是单张图片;prompt/model/image 仍在 item 层的老字段里
|
|
5
|
+
// (aigc_image_params / image.large_images / common_attr)。完成态以「拿到 large_images
|
|
6
|
+
// 的图片 URL」判定(状态码 102→144/50 已漂移,别再按魔法数字判),出图即完成。
|
|
3
7
|
const res = await fetch('/mweb/v1/get_history?aid=513695&device_platform=web®ion=cn&da_version=3.3.11&web_version=7.5.0&aigc_features=app_lip_sync', {
|
|
4
8
|
method: 'POST',
|
|
5
9
|
credentials: 'include',
|
|
6
10
|
headers: { 'Content-Type': 'application/json' },
|
|
7
|
-
body: JSON.stringify({ cursor: '', count: limit, need_page_item: true, need_aigc_data: true, aigc_mode_list: ['workbench'] })
|
|
11
|
+
body: JSON.stringify({ cursor: '', count: Math.max(limit, 10), need_page_item: true, need_aigc_data: true, aigc_mode_list: ['workbench'] })
|
|
8
12
|
});
|
|
9
13
|
const data = await res.json();
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
14
|
+
const records = data?.data?.records_list || [];
|
|
15
|
+
const rows = [];
|
|
16
|
+
for (const rec of records) {
|
|
17
|
+
for (const item of (rec.item_list || [])) {
|
|
18
|
+
const params = item.aigc_image_params?.text2image_params || {};
|
|
19
|
+
const imageUrl = item.image?.large_images?.[0]?.image_url || item.common_attr?.cover_url || '';
|
|
20
|
+
rows.push({
|
|
21
|
+
prompt: params.prompt || item.common_attr?.title || rec.fail_starling_message || 'N/A',
|
|
22
|
+
model: (rec.model_info?.model_name) || params.model_config?.model_name || 'unknown',
|
|
23
|
+
status: imageUrl ? 'completed' : 'pending',
|
|
24
|
+
image_url: imageUrl,
|
|
25
|
+
created_at: new Date((item.common_attr?.create_time || rec.finish_time || 0) * 1000).toLocaleString('zh-CN'),
|
|
26
|
+
});
|
|
27
|
+
if (rows.length >= limit) return rows;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return rows;
|
|
22
31
|
})()
|
|
23
32
|
`},{map:{prompt:"${{ item.prompt }}",model:"${{ item.model }}",status:"${{ item.status }}",image_url:"${{ item.image_url }}",created_at:"${{ item.created_at }}"}},{limit:"${{ args.limit }}"}]});
|
package/clis/pixiv/auth.js
CHANGED
|
@@ -1,25 +1,16 @@
|
|
|
1
1
|
import{AuthRequiredError as D,CommandExecutionError as F}from"@jackwener/opencli/errors";import{registerSiteAuthCommands as K}from"../_shared/site-auth.js";async function G(B){return(await B.getCookies({url:"https://www.pixiv.net"})).some((H)=>H.name==="PHPSESSID"&&/^\d+_/.test(H.value||""))}async function J(B){if(!await G(B))throw new D("pixiv.net","Pixiv PHPSESSID cookie missing");await B.goto("https://www.pixiv.net/");await B.wait(2);const z=await B.evaluate(`(async () => {
|
|
2
2
|
try {
|
|
3
|
-
const
|
|
4
|
-
let userData = null;
|
|
5
|
-
if (meta) { try { userData = JSON.parse(meta); } catch {} }
|
|
6
|
-
const u = userData?.userData;
|
|
7
|
-
if (u?.id) {
|
|
8
|
-
return { ok: true, user_id: String(u.id), name: String(u.name || u.account || '') };
|
|
9
|
-
}
|
|
10
|
-
const r = await fetch('/ajax/user/extra', { credentials: 'include', headers: { Accept: 'application/json' } });
|
|
3
|
+
const r = await fetch('/touch/ajax/user/self/status', { credentials: 'include', headers: { Accept: 'application/json' } });
|
|
11
4
|
if (r.status === 401 || r.status === 403) {
|
|
12
|
-
return { kind: 'auth', detail: 'Pixiv /
|
|
5
|
+
return { kind: 'auth', detail: 'Pixiv self/status HTTP ' + r.status };
|
|
13
6
|
}
|
|
14
7
|
if (!r.ok) return { kind: 'http', httpStatus: r.status };
|
|
15
|
-
const d = await r.json();
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
if (!uid) {
|
|
20
|
-
return { kind: 'auth', detail: 'Pixiv PHPSESSID prefix unparseable' };
|
|
8
|
+
const d = await r.json().catch(() => null);
|
|
9
|
+
const u = d?.body?.user_status;
|
|
10
|
+
if (d?.error || !u || u.is_loggedin === false || !u.user_id) {
|
|
11
|
+
return { kind: 'auth', detail: 'Pixiv self/status reports anonymous' };
|
|
21
12
|
}
|
|
22
|
-
return { ok: true, user_id:
|
|
13
|
+
return { ok: true, user_id: String(u.user_id), name: String(u.user_name || u.user_account || '') };
|
|
23
14
|
} catch (e) {
|
|
24
15
|
return { kind: 'exception', detail: String(e && e.message || e) };
|
|
25
16
|
}
|
package/clis/suno/auth.js
CHANGED
|
@@ -1,24 +1,20 @@
|
|
|
1
1
|
import{AuthRequiredError as D,CommandExecutionError as F}from"@jackwener/opencli/errors";import{registerSiteAuthCommands as K}from"../_shared/site-auth.js";async function G(B){return(await B.getCookies({url:"https://clerk.suno.com"})).some((H)=>H.name==="__session"&&H.value)}async function J(B){if(!await G(B))throw new D("suno.com","Suno Clerk __session/__client cookie missing");await B.goto("https://suno.com/");await B.wait(2);const z=await B.evaluate(`(async () => {
|
|
2
2
|
try {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
});
|
|
7
|
-
if (r.status === 401 || r.status === 403) {
|
|
8
|
-
return { kind: 'auth', detail: 'clerk.suno.com /v1/client HTTP ' + r.status };
|
|
3
|
+
for (let i = 0; i < 20; i += 1) {
|
|
4
|
+
if (window.Clerk && window.Clerk.loaded) break;
|
|
5
|
+
await new Promise(r => setTimeout(r, 250));
|
|
9
6
|
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
7
|
+
const C = window.Clerk;
|
|
8
|
+
if (!C) return { kind: 'exception', detail: 'window.Clerk never mounted' };
|
|
9
|
+
const user = C.user;
|
|
10
|
+
const session = C.session;
|
|
11
|
+
if (!user || !session) {
|
|
12
|
+
return { kind: 'auth', detail: 'Suno Clerk mounted but no active user/session — anonymous' };
|
|
15
13
|
}
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
-
return { ok: true, user_id: String(user.id), name: String(user.username || '') };
|
|
14
|
+
const email = user.primaryEmailAddress?.emailAddress
|
|
15
|
+
|| user.emailAddresses?.[0]?.emailAddress
|
|
16
|
+
|| '';
|
|
17
|
+
return { ok: true, user_id: String(user.id), name: String(user.username || email || '') };
|
|
22
18
|
} catch (e) {
|
|
23
19
|
return { kind: 'exception', detail: String(e && e.message || e) };
|
|
24
20
|
}
|