@jackwener/opencli 0.7.2 โ 0.7.3
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/README.md +2 -1
- package/README.zh-CN.md +1 -0
- package/SKILL.md +3 -0
- package/dist/cli-manifest.json +195 -22
- package/dist/clis/linkedin/search.d.ts +1 -0
- package/dist/clis/linkedin/search.js +366 -0
- package/dist/clis/reddit/read.d.ts +1 -0
- package/dist/clis/reddit/read.js +184 -0
- package/dist/clis/youtube/transcript-group.d.ts +44 -0
- package/dist/clis/youtube/transcript-group.js +226 -0
- package/dist/clis/youtube/transcript-group.test.d.ts +1 -0
- package/dist/clis/youtube/transcript-group.test.js +99 -0
- package/dist/clis/youtube/transcript.d.ts +1 -0
- package/dist/clis/youtube/transcript.js +264 -0
- package/dist/clis/youtube/utils.d.ts +8 -0
- package/dist/clis/youtube/utils.js +28 -0
- package/dist/clis/youtube/video.d.ts +1 -0
- package/dist/clis/youtube/video.js +114 -0
- package/package.json +1 -1
- package/src/clis/linkedin/search.ts +416 -0
- package/src/clis/reddit/read.ts +186 -0
- package/src/clis/youtube/transcript-group.test.ts +108 -0
- package/src/clis/youtube/transcript-group.ts +287 -0
- package/src/clis/youtube/transcript.ts +280 -0
- package/src/clis/youtube/utils.ts +28 -0
- package/src/clis/youtube/video.ts +116 -0
- package/dist/clis/reddit/read.yaml +0 -76
- package/src/clis/reddit/read.yaml +0 -76
package/README.md
CHANGED
|
@@ -141,7 +141,8 @@ npm install -g @jackwener/opencli@latest
|
|
|
141
141
|
| **weibo** | `hot` | ๐ Browser |
|
|
142
142
|
| **boss** | `search` `detail` | ๐ Browser |
|
|
143
143
|
| **coupang** | `search` `add-to-cart` | ๐ Browser |
|
|
144
|
-
| **youtube** | `search` | ๐ Browser |
|
|
144
|
+
| **youtube** | `search` `video` `transcript` | ๐ Browser |
|
|
145
|
+
| **linkedin** | `search` | ๐ Browser |
|
|
145
146
|
| **yahoo-finance** | `quote` | ๐ Browser |
|
|
146
147
|
| **reuters** | `search` | ๐ Browser |
|
|
147
148
|
| **smzdm** | `search` | ๐ Browser |
|
package/README.zh-CN.md
CHANGED
|
@@ -141,6 +141,7 @@ npm install -g @jackwener/opencli@latest
|
|
|
141
141
|
| **boss** | `search` `detail` | ๐ ๆต่งๅจ |
|
|
142
142
|
| **coupang** | `search` `add-to-cart` | ๐ ๆต่งๅจ |
|
|
143
143
|
| **youtube** | `search` | ๐ ๆต่งๅจ |
|
|
144
|
+
| **linkedin** | `search` | ๐ ๆต่งๅจ |
|
|
144
145
|
| **yahoo-finance** | `quote` | ๐ ๆต่งๅจ |
|
|
145
146
|
| **reuters** | `search` | ๐ ๆต่งๅจ |
|
|
146
147
|
| **smzdm** | `search` | ๐ ๆต่งๅจ |
|
package/SKILL.md
CHANGED
|
@@ -134,6 +134,9 @@ opencli boss search --query "AI agent" # ๆ็ดข่ไฝ
|
|
|
134
134
|
|
|
135
135
|
# YouTube (browser)
|
|
136
136
|
opencli youtube search --query "rust" # ๆ็ดข่ง้ข
|
|
137
|
+
opencli youtube video --url "https://www.youtube.com/watch?v=xxx" # ่ง้ขๅ
ๆฐๆฎ๏ผๆ ้ขใๆญๆพ้ใๆ่ฟฐ็ญ๏ผ
|
|
138
|
+
opencli youtube transcript --url "https://www.youtube.com/watch?v=xxx" # ่ทๅ่ง้ขๅญๅน/่ฝฌๅฝ
|
|
139
|
+
opencli youtube transcript --url "xxx" --lang zh-Hans --mode raw # ๆๅฎ่ฏญ่จ + ๅๅงๆถ้ดๆณๆจกๅผ
|
|
137
140
|
|
|
138
141
|
# Yahoo Finance (browser)
|
|
139
142
|
opencli yahoo-finance quote --symbol AAPL # ่ก็ฅจ่กๆ
|
package/dist/cli-manifest.json
CHANGED
|
@@ -680,6 +680,90 @@
|
|
|
680
680
|
],
|
|
681
681
|
"type": "yaml"
|
|
682
682
|
},
|
|
683
|
+
{
|
|
684
|
+
"site": "linkedin",
|
|
685
|
+
"name": "search",
|
|
686
|
+
"description": "",
|
|
687
|
+
"strategy": "header",
|
|
688
|
+
"browser": true,
|
|
689
|
+
"args": [
|
|
690
|
+
{
|
|
691
|
+
"name": "query",
|
|
692
|
+
"type": "string",
|
|
693
|
+
"required": true,
|
|
694
|
+
"help": "Job search keywords"
|
|
695
|
+
},
|
|
696
|
+
{
|
|
697
|
+
"name": "location",
|
|
698
|
+
"type": "string",
|
|
699
|
+
"required": false,
|
|
700
|
+
"help": "Location text such as San Francisco Bay Area"
|
|
701
|
+
},
|
|
702
|
+
{
|
|
703
|
+
"name": "limit",
|
|
704
|
+
"type": "int",
|
|
705
|
+
"default": 10,
|
|
706
|
+
"required": false,
|
|
707
|
+
"help": "Number of jobs to return (max 100)"
|
|
708
|
+
},
|
|
709
|
+
{
|
|
710
|
+
"name": "start",
|
|
711
|
+
"type": "int",
|
|
712
|
+
"default": 0,
|
|
713
|
+
"required": false,
|
|
714
|
+
"help": "Result offset for pagination"
|
|
715
|
+
},
|
|
716
|
+
{
|
|
717
|
+
"name": "details",
|
|
718
|
+
"type": "bool",
|
|
719
|
+
"default": false,
|
|
720
|
+
"required": false,
|
|
721
|
+
"help": "Include full job description and apply URL (slower)"
|
|
722
|
+
},
|
|
723
|
+
{
|
|
724
|
+
"name": "company",
|
|
725
|
+
"type": "string",
|
|
726
|
+
"required": false,
|
|
727
|
+
"help": "Comma-separated company names or LinkedIn company IDs"
|
|
728
|
+
},
|
|
729
|
+
{
|
|
730
|
+
"name": "experience_level",
|
|
731
|
+
"type": "string",
|
|
732
|
+
"required": false,
|
|
733
|
+
"help": "Comma-separated: internship, entry, associate, mid-senior, director, executive"
|
|
734
|
+
},
|
|
735
|
+
{
|
|
736
|
+
"name": "job_type",
|
|
737
|
+
"type": "string",
|
|
738
|
+
"required": false,
|
|
739
|
+
"help": "Comma-separated: full-time, part-time, contract, temporary, volunteer, internship, other"
|
|
740
|
+
},
|
|
741
|
+
{
|
|
742
|
+
"name": "date_posted",
|
|
743
|
+
"type": "string",
|
|
744
|
+
"required": false,
|
|
745
|
+
"help": "One of: any, month, week, 24h"
|
|
746
|
+
},
|
|
747
|
+
{
|
|
748
|
+
"name": "remote",
|
|
749
|
+
"type": "string",
|
|
750
|
+
"required": false,
|
|
751
|
+
"help": "Comma-separated: on-site, hybrid, remote"
|
|
752
|
+
}
|
|
753
|
+
],
|
|
754
|
+
"type": "ts",
|
|
755
|
+
"modulePath": "linkedin/search.js",
|
|
756
|
+
"domain": "www.linkedin.com",
|
|
757
|
+
"columns": [
|
|
758
|
+
"rank",
|
|
759
|
+
"title",
|
|
760
|
+
"company",
|
|
761
|
+
"location",
|
|
762
|
+
"listed",
|
|
763
|
+
"salary",
|
|
764
|
+
"url"
|
|
765
|
+
]
|
|
766
|
+
},
|
|
683
767
|
{
|
|
684
768
|
"site": "reddit",
|
|
685
769
|
"name": "comment",
|
|
@@ -858,19 +942,18 @@
|
|
|
858
942
|
"site": "reddit",
|
|
859
943
|
"name": "read",
|
|
860
944
|
"description": "Read a Reddit post and its comments",
|
|
861
|
-
"domain": "reddit.com",
|
|
862
945
|
"strategy": "cookie",
|
|
863
946
|
"browser": true,
|
|
864
947
|
"args": [
|
|
865
948
|
{
|
|
866
949
|
"name": "post_id",
|
|
867
|
-
"type": "
|
|
950
|
+
"type": "str",
|
|
868
951
|
"required": true,
|
|
869
952
|
"help": "Post ID (e.g. 1abc123) or full URL"
|
|
870
953
|
},
|
|
871
954
|
{
|
|
872
955
|
"name": "sort",
|
|
873
|
-
"type": "
|
|
956
|
+
"type": "str",
|
|
874
957
|
"default": "best",
|
|
875
958
|
"required": false,
|
|
876
959
|
"help": "Comment sort: best, top, new, controversial, old, qa"
|
|
@@ -880,32 +963,39 @@
|
|
|
880
963
|
"type": "int",
|
|
881
964
|
"default": 25,
|
|
882
965
|
"required": false,
|
|
883
|
-
"help": "Number of top-level comments
|
|
884
|
-
}
|
|
885
|
-
],
|
|
886
|
-
"columns": [
|
|
887
|
-
"type",
|
|
888
|
-
"author",
|
|
889
|
-
"score",
|
|
890
|
-
"text"
|
|
891
|
-
],
|
|
892
|
-
"pipeline": [
|
|
966
|
+
"help": "Number of top-level comments"
|
|
967
|
+
},
|
|
893
968
|
{
|
|
894
|
-
"
|
|
969
|
+
"name": "depth",
|
|
970
|
+
"type": "int",
|
|
971
|
+
"default": 2,
|
|
972
|
+
"required": false,
|
|
973
|
+
"help": "Max reply depth (1=no replies, 2=one level of replies, etc.)"
|
|
895
974
|
},
|
|
896
975
|
{
|
|
897
|
-
"
|
|
976
|
+
"name": "replies",
|
|
977
|
+
"type": "int",
|
|
978
|
+
"default": 5,
|
|
979
|
+
"required": false,
|
|
980
|
+
"help": "Max replies shown per comment at each level (sorted by score)"
|
|
898
981
|
},
|
|
899
982
|
{
|
|
900
|
-
"
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
}
|
|
983
|
+
"name": "max_length",
|
|
984
|
+
"type": "int",
|
|
985
|
+
"default": 2000,
|
|
986
|
+
"required": false,
|
|
987
|
+
"help": "Max characters per comment body (min 100)"
|
|
906
988
|
}
|
|
907
989
|
],
|
|
908
|
-
"type": "
|
|
990
|
+
"type": "ts",
|
|
991
|
+
"modulePath": "reddit/read.js",
|
|
992
|
+
"domain": "reddit.com",
|
|
993
|
+
"columns": [
|
|
994
|
+
"type",
|
|
995
|
+
"author",
|
|
996
|
+
"score",
|
|
997
|
+
"text"
|
|
998
|
+
]
|
|
909
999
|
},
|
|
910
1000
|
{
|
|
911
1001
|
"site": "reddit",
|
|
@@ -2639,6 +2729,89 @@
|
|
|
2639
2729
|
"url"
|
|
2640
2730
|
]
|
|
2641
2731
|
},
|
|
2732
|
+
{
|
|
2733
|
+
"site": "youtube",
|
|
2734
|
+
"name": "transcript-group",
|
|
2735
|
+
"description": "",
|
|
2736
|
+
"strategy": "cookie",
|
|
2737
|
+
"browser": true,
|
|
2738
|
+
"args": [],
|
|
2739
|
+
"type": "ts",
|
|
2740
|
+
"modulePath": "youtube/transcript-group.js"
|
|
2741
|
+
},
|
|
2742
|
+
{
|
|
2743
|
+
"site": "youtube",
|
|
2744
|
+
"name": "transcript-group.test",
|
|
2745
|
+
"description": "",
|
|
2746
|
+
"strategy": "cookie",
|
|
2747
|
+
"browser": true,
|
|
2748
|
+
"args": [],
|
|
2749
|
+
"type": "ts",
|
|
2750
|
+
"modulePath": "youtube/transcript-group.test.js"
|
|
2751
|
+
},
|
|
2752
|
+
{
|
|
2753
|
+
"site": "youtube",
|
|
2754
|
+
"name": "transcript",
|
|
2755
|
+
"description": "Get YouTube video transcript/subtitles",
|
|
2756
|
+
"strategy": "cookie",
|
|
2757
|
+
"browser": true,
|
|
2758
|
+
"args": [
|
|
2759
|
+
{
|
|
2760
|
+
"name": "url",
|
|
2761
|
+
"type": "str",
|
|
2762
|
+
"required": true,
|
|
2763
|
+
"help": "YouTube video URL or video ID"
|
|
2764
|
+
},
|
|
2765
|
+
{
|
|
2766
|
+
"name": "lang",
|
|
2767
|
+
"type": "str",
|
|
2768
|
+
"required": false,
|
|
2769
|
+
"help": "Language code (e.g. en, zh-Hans). Omit to auto-select"
|
|
2770
|
+
},
|
|
2771
|
+
{
|
|
2772
|
+
"name": "mode",
|
|
2773
|
+
"type": "str",
|
|
2774
|
+
"default": "grouped",
|
|
2775
|
+
"required": false,
|
|
2776
|
+
"help": "Output mode: grouped (readable paragraphs) or raw (every segment)"
|
|
2777
|
+
}
|
|
2778
|
+
],
|
|
2779
|
+
"type": "ts",
|
|
2780
|
+
"modulePath": "youtube/transcript.js",
|
|
2781
|
+
"domain": "www.youtube.com"
|
|
2782
|
+
},
|
|
2783
|
+
{
|
|
2784
|
+
"site": "youtube",
|
|
2785
|
+
"name": "utils",
|
|
2786
|
+
"description": "",
|
|
2787
|
+
"strategy": "cookie",
|
|
2788
|
+
"browser": true,
|
|
2789
|
+
"args": [],
|
|
2790
|
+
"type": "ts",
|
|
2791
|
+
"modulePath": "youtube/utils.js"
|
|
2792
|
+
},
|
|
2793
|
+
{
|
|
2794
|
+
"site": "youtube",
|
|
2795
|
+
"name": "video",
|
|
2796
|
+
"description": "Get YouTube video metadata (title, views, description, etc.)",
|
|
2797
|
+
"strategy": "cookie",
|
|
2798
|
+
"browser": true,
|
|
2799
|
+
"args": [
|
|
2800
|
+
{
|
|
2801
|
+
"name": "url",
|
|
2802
|
+
"type": "str",
|
|
2803
|
+
"required": true,
|
|
2804
|
+
"help": "YouTube video URL or video ID"
|
|
2805
|
+
}
|
|
2806
|
+
],
|
|
2807
|
+
"type": "ts",
|
|
2808
|
+
"modulePath": "youtube/video.js",
|
|
2809
|
+
"domain": "www.youtube.com",
|
|
2810
|
+
"columns": [
|
|
2811
|
+
"field",
|
|
2812
|
+
"value"
|
|
2813
|
+
]
|
|
2814
|
+
},
|
|
2642
2815
|
{
|
|
2643
2816
|
"site": "zhihu",
|
|
2644
2817
|
"name": "hot",
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,366 @@
|
|
|
1
|
+
import { cli, Strategy } from '../../registry.js';
|
|
2
|
+
// โโ Filter value mappings โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
3
|
+
const EXPERIENCE_LEVELS = {
|
|
4
|
+
internship: '1',
|
|
5
|
+
entry: '2',
|
|
6
|
+
'entry-level': '2',
|
|
7
|
+
associate: '3',
|
|
8
|
+
mid: '4',
|
|
9
|
+
senior: '4',
|
|
10
|
+
'mid-senior': '4',
|
|
11
|
+
'mid-senior-level': '4',
|
|
12
|
+
director: '5',
|
|
13
|
+
executive: '6',
|
|
14
|
+
};
|
|
15
|
+
const JOB_TYPES = {
|
|
16
|
+
'full-time': 'F',
|
|
17
|
+
fulltime: 'F',
|
|
18
|
+
full: 'F',
|
|
19
|
+
'part-time': 'P',
|
|
20
|
+
parttime: 'P',
|
|
21
|
+
part: 'P',
|
|
22
|
+
contract: 'C',
|
|
23
|
+
temporary: 'T',
|
|
24
|
+
temp: 'T',
|
|
25
|
+
volunteer: 'V',
|
|
26
|
+
internship: 'I',
|
|
27
|
+
other: 'O',
|
|
28
|
+
};
|
|
29
|
+
const DATE_POSTED = {
|
|
30
|
+
any: 'on',
|
|
31
|
+
month: 'r2592000',
|
|
32
|
+
'past-month': 'r2592000',
|
|
33
|
+
week: 'r604800',
|
|
34
|
+
'past-week': 'r604800',
|
|
35
|
+
day: 'r86400',
|
|
36
|
+
'24h': 'r86400',
|
|
37
|
+
'past-24h': 'r86400',
|
|
38
|
+
};
|
|
39
|
+
const REMOTE_TYPES = {
|
|
40
|
+
onsite: '1',
|
|
41
|
+
'on-site': '1',
|
|
42
|
+
hybrid: '3',
|
|
43
|
+
remote: '2',
|
|
44
|
+
};
|
|
45
|
+
// โโ Helpers โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
46
|
+
function parseCsvArg(value) {
|
|
47
|
+
if (value === undefined || value === null || value === '')
|
|
48
|
+
return [];
|
|
49
|
+
return String(value)
|
|
50
|
+
.split(',')
|
|
51
|
+
.map(item => item.trim())
|
|
52
|
+
.filter(Boolean);
|
|
53
|
+
}
|
|
54
|
+
function mapFilterValues(input, mapping, label) {
|
|
55
|
+
const values = parseCsvArg(input);
|
|
56
|
+
const resolved = values.map(value => {
|
|
57
|
+
const key = value.toLowerCase();
|
|
58
|
+
const mapped = mapping[key];
|
|
59
|
+
if (!mapped)
|
|
60
|
+
throw new Error(`Unsupported ${label}: ${value}`);
|
|
61
|
+
return mapped;
|
|
62
|
+
});
|
|
63
|
+
return [...new Set(resolved)];
|
|
64
|
+
}
|
|
65
|
+
function normalizeWhitespace(value) {
|
|
66
|
+
return String(value ?? '').replace(/\s+/g, ' ').trim();
|
|
67
|
+
}
|
|
68
|
+
function decodeLinkedinRedirect(url) {
|
|
69
|
+
if (!url)
|
|
70
|
+
return '';
|
|
71
|
+
try {
|
|
72
|
+
const parsed = new URL(url);
|
|
73
|
+
if (parsed.pathname === '/redir/redirect/') {
|
|
74
|
+
return parsed.searchParams.get('url') || url;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
catch { }
|
|
78
|
+
return url;
|
|
79
|
+
}
|
|
80
|
+
function buildVoyagerSearchQuery(input) {
|
|
81
|
+
const hasFilters = input.companyIds.length ||
|
|
82
|
+
input.experienceLevels.length ||
|
|
83
|
+
input.jobTypes.length ||
|
|
84
|
+
input.datePostedValues.length ||
|
|
85
|
+
input.remoteTypes.length;
|
|
86
|
+
const parts = [
|
|
87
|
+
'origin:' + (hasFilters ? 'JOB_SEARCH_PAGE_JOB_FILTER' : 'JOB_SEARCH_PAGE_OTHER_ENTRY'),
|
|
88
|
+
'keywords:' + input.keywords,
|
|
89
|
+
];
|
|
90
|
+
if (input.location) {
|
|
91
|
+
parts.push('locationUnion:(seoLocation:(location:' + input.location + '))');
|
|
92
|
+
}
|
|
93
|
+
const filters = [];
|
|
94
|
+
if (input.companyIds.length)
|
|
95
|
+
filters.push('company:List(' + input.companyIds.join(',') + ')');
|
|
96
|
+
if (input.experienceLevels.length)
|
|
97
|
+
filters.push('experience:List(' + input.experienceLevels.join(',') + ')');
|
|
98
|
+
if (input.jobTypes.length)
|
|
99
|
+
filters.push('jobType:List(' + input.jobTypes.join(',') + ')');
|
|
100
|
+
if (input.datePostedValues.length)
|
|
101
|
+
filters.push('timePostedRange:List(' + input.datePostedValues.join(',') + ')');
|
|
102
|
+
if (input.remoteTypes.length)
|
|
103
|
+
filters.push('workplaceType:List(' + input.remoteTypes.join(',') + ')');
|
|
104
|
+
if (filters.length)
|
|
105
|
+
parts.push('selectedFilters:(' + filters.join(',') + ')');
|
|
106
|
+
parts.push('spellCorrectionEnabled:true');
|
|
107
|
+
return '(' + parts.join(',') + ')';
|
|
108
|
+
}
|
|
109
|
+
function buildVoyagerUrl(input, offset, count) {
|
|
110
|
+
const params = new URLSearchParams({
|
|
111
|
+
decorationId: 'com.linkedin.voyager.dash.deco.jobs.search.JobSearchCardsCollection-220',
|
|
112
|
+
count: String(count),
|
|
113
|
+
q: 'jobSearch',
|
|
114
|
+
});
|
|
115
|
+
const query = encodeURIComponent(buildVoyagerSearchQuery(input))
|
|
116
|
+
.replace(/%3A/gi, ':')
|
|
117
|
+
.replace(/%2C/gi, ',')
|
|
118
|
+
.replace(/%28/gi, '(')
|
|
119
|
+
.replace(/%29/gi, ')');
|
|
120
|
+
return '/voyager/api/voyagerJobsDashJobCards?' + params.toString() + '&query=' + query + '&start=' + offset;
|
|
121
|
+
}
|
|
122
|
+
// โโ Company ID resolution (requires DOM interaction) โโโโโโโโโโโโโโโโโโ
|
|
123
|
+
async function resolveCompanyIds(page, input) {
|
|
124
|
+
const rawValues = parseCsvArg(input);
|
|
125
|
+
const ids = new Set();
|
|
126
|
+
const names = [];
|
|
127
|
+
for (const value of rawValues) {
|
|
128
|
+
if (/^\d+$/.test(value))
|
|
129
|
+
ids.add(value);
|
|
130
|
+
else
|
|
131
|
+
names.push(value);
|
|
132
|
+
}
|
|
133
|
+
if (!names.length)
|
|
134
|
+
return [...ids];
|
|
135
|
+
const resolved = await page.evaluate(`(async () => {
|
|
136
|
+
const targets = ${JSON.stringify(names)};
|
|
137
|
+
const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms));
|
|
138
|
+
const normalize = (v) => (v || '').toLowerCase().replace(/\\s+/g, ' ').trim();
|
|
139
|
+
|
|
140
|
+
// Open "All filters" panel to expose company filter inputs
|
|
141
|
+
const allBtn = [...document.querySelectorAll('button')]
|
|
142
|
+
.find(b => ((b.innerText || '').trim().replace(/\\s+/g, ' ')) === 'All filters');
|
|
143
|
+
if (allBtn) { allBtn.click(); await sleep(300); }
|
|
144
|
+
|
|
145
|
+
const getCompanyMap = () => {
|
|
146
|
+
const map = {};
|
|
147
|
+
for (const el of document.querySelectorAll('input[name="company-filter-value"]')) {
|
|
148
|
+
const text = (el.parentElement?.innerText || el.closest('label')?.innerText || '')
|
|
149
|
+
.replace(/\\s+/g, ' ').trim().replace(/\\s*Filter by.*$/i, '').trim();
|
|
150
|
+
if (text) map[normalize(text)] = el.value;
|
|
151
|
+
}
|
|
152
|
+
return map;
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
const match = (map, name) => {
|
|
156
|
+
const n = normalize(name);
|
|
157
|
+
if (map[n]) return map[n];
|
|
158
|
+
const k = Object.keys(map).find(e => e === n || e.includes(n) || n.includes(e));
|
|
159
|
+
return k ? map[k] : null;
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
const results = {};
|
|
163
|
+
let map = getCompanyMap();
|
|
164
|
+
|
|
165
|
+
for (const name of targets) {
|
|
166
|
+
let found = match(map, name);
|
|
167
|
+
if (!found) {
|
|
168
|
+
const inp = [...document.querySelectorAll('input')]
|
|
169
|
+
.find(el => el.getAttribute('aria-label') === 'Add a company');
|
|
170
|
+
if (inp) {
|
|
171
|
+
inp.focus();
|
|
172
|
+
inp.value = name;
|
|
173
|
+
inp.dispatchEvent(new Event('input', { bubbles: true }));
|
|
174
|
+
inp.dispatchEvent(new KeyboardEvent('keyup', { key: 'Enter', bubbles: true }));
|
|
175
|
+
await sleep(1200);
|
|
176
|
+
map = getCompanyMap();
|
|
177
|
+
found = match(map, name);
|
|
178
|
+
inp.value = '';
|
|
179
|
+
inp.dispatchEvent(new Event('input', { bubbles: true }));
|
|
180
|
+
await sleep(100);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
results[name] = found || null;
|
|
184
|
+
}
|
|
185
|
+
return results;
|
|
186
|
+
})()`);
|
|
187
|
+
const unresolved = [];
|
|
188
|
+
for (const name of names) {
|
|
189
|
+
const id = resolved?.[name];
|
|
190
|
+
if (id)
|
|
191
|
+
ids.add(id);
|
|
192
|
+
else
|
|
193
|
+
unresolved.push(name);
|
|
194
|
+
}
|
|
195
|
+
if (unresolved.length) {
|
|
196
|
+
throw new Error(`Could not resolve LinkedIn company filter: ${unresolved.join(', ')}`);
|
|
197
|
+
}
|
|
198
|
+
return [...ids];
|
|
199
|
+
}
|
|
200
|
+
// โโ Voyager API fetch (runs inside page context for cookie access) โโโโ
|
|
201
|
+
async function fetchJobCards(page, input) {
|
|
202
|
+
const MAX_BATCH = 25;
|
|
203
|
+
const allJobs = [];
|
|
204
|
+
let offset = input.start;
|
|
205
|
+
while (allJobs.length < input.limit) {
|
|
206
|
+
const count = Math.min(MAX_BATCH, input.limit - allJobs.length);
|
|
207
|
+
const apiPath = buildVoyagerUrl(input, offset, count);
|
|
208
|
+
const batch = await page.evaluate(`(async () => {
|
|
209
|
+
const jsession = document.cookie.split(';').map(p => p.trim())
|
|
210
|
+
.find(p => p.startsWith('JSESSIONID='))?.slice('JSESSIONID='.length);
|
|
211
|
+
if (!jsession) return { error: 'LinkedIn JSESSIONID cookie not found. Please sign in to LinkedIn in the browser.' };
|
|
212
|
+
|
|
213
|
+
const csrf = jsession.replace(/^"|"$/g, '');
|
|
214
|
+
const res = await fetch(${JSON.stringify(apiPath)}, {
|
|
215
|
+
credentials: 'include',
|
|
216
|
+
headers: { 'csrf-token': csrf, 'x-restli-protocol-version': '2.0.0' },
|
|
217
|
+
});
|
|
218
|
+
if (!res.ok) {
|
|
219
|
+
const text = await res.text();
|
|
220
|
+
return { error: 'LinkedIn API error: HTTP ' + res.status + ' ' + text.slice(0, 200) };
|
|
221
|
+
}
|
|
222
|
+
return res.json();
|
|
223
|
+
})()`);
|
|
224
|
+
if (!batch || batch.error) {
|
|
225
|
+
throw new Error(batch?.error || 'LinkedIn search returned an unexpected response');
|
|
226
|
+
}
|
|
227
|
+
const elements = Array.isArray(batch?.elements) ? batch.elements : [];
|
|
228
|
+
if (elements.length === 0)
|
|
229
|
+
break;
|
|
230
|
+
for (const element of elements) {
|
|
231
|
+
const card = element?.jobCardUnion?.jobPostingCard;
|
|
232
|
+
if (!card)
|
|
233
|
+
continue;
|
|
234
|
+
// Extract job ID from URN fields
|
|
235
|
+
const jobId = [card.jobPostingUrn, card.jobPosting?.entityUrn, card.entityUrn]
|
|
236
|
+
.filter(Boolean)
|
|
237
|
+
.map(s => String(s).match(/(\d+)/)?.[1])
|
|
238
|
+
.find(Boolean) ?? '';
|
|
239
|
+
// Extract listed date
|
|
240
|
+
const listedItem = (card.footerItems || []).find((i) => i?.type === 'LISTED_DATE' && i?.timeAt);
|
|
241
|
+
const listed = listedItem?.timeAt ? new Date(listedItem.timeAt).toISOString().slice(0, 10) : '';
|
|
242
|
+
allJobs.push({
|
|
243
|
+
title: card.jobPostingTitle || card.title?.text || '',
|
|
244
|
+
company: card.primaryDescription?.text || '',
|
|
245
|
+
location: card.secondaryDescription?.text || '',
|
|
246
|
+
listed,
|
|
247
|
+
salary: card.tertiaryDescription?.text || '',
|
|
248
|
+
url: jobId ? 'https://www.linkedin.com/jobs/view/' + jobId : '',
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
if (elements.length < count)
|
|
252
|
+
break;
|
|
253
|
+
offset += elements.length;
|
|
254
|
+
}
|
|
255
|
+
return allJobs.slice(0, input.limit).map((item, index) => ({
|
|
256
|
+
rank: input.start + index + 1,
|
|
257
|
+
...item,
|
|
258
|
+
}));
|
|
259
|
+
}
|
|
260
|
+
// โโ Job detail enrichment (--details flag) โโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
261
|
+
async function enrichJobDetails(page, jobs) {
|
|
262
|
+
const enriched = [];
|
|
263
|
+
for (let i = 0; i < jobs.length; i++) {
|
|
264
|
+
const job = jobs[i];
|
|
265
|
+
console.error(`[opencli:linkedin] Fetching details ${i + 1}/${jobs.length}: ${job.title}`);
|
|
266
|
+
if (!job.url) {
|
|
267
|
+
enriched.push({ ...job, description: '', apply_url: '' });
|
|
268
|
+
continue;
|
|
269
|
+
}
|
|
270
|
+
try {
|
|
271
|
+
await page.goto(job.url);
|
|
272
|
+
await page.wait({ text: 'About the job', timeout: 8 });
|
|
273
|
+
// Expand "Show more" button if present
|
|
274
|
+
await page.evaluate(`(() => {
|
|
275
|
+
const norm = (v) => (v || '').replace(/\\s+/g, ' ').trim().toLowerCase();
|
|
276
|
+
const section = [...document.querySelectorAll('div, section, article')]
|
|
277
|
+
.find(el => norm(el.querySelector('h1,h2,h3,h4')?.textContent || '') === 'about the job');
|
|
278
|
+
const btn = [...(section?.querySelectorAll('button, a[role="button"]') || [])]
|
|
279
|
+
.find(el => /more/.test(norm(el.textContent || '')) || /more/.test(norm(el.getAttribute('aria-label') || '')));
|
|
280
|
+
if (btn) btn.click();
|
|
281
|
+
})()`);
|
|
282
|
+
await page.wait(1);
|
|
283
|
+
// Extract description and apply URL
|
|
284
|
+
const detail = await page.evaluate(`(() => {
|
|
285
|
+
const norm = (v) => (v || '').replace(/\\s+/g, ' ').trim();
|
|
286
|
+
// Find the most specific (shortest) container with "About the job" heading
|
|
287
|
+
// Shortest = most specific DOM node, avoiding outer wrappers that include unrelated text
|
|
288
|
+
const candidates = [...document.querySelectorAll('div, section, article')]
|
|
289
|
+
.map(el => ({
|
|
290
|
+
heading: norm(el.querySelector('h1,h2,h3,h4')?.textContent || ''),
|
|
291
|
+
text: norm(el.innerText || ''),
|
|
292
|
+
}))
|
|
293
|
+
.filter(c => c.text && c.heading.toLowerCase() === 'about the job' && c.text.length > 'About the job'.length)
|
|
294
|
+
.sort((a, b) => a.text.length - b.text.length);
|
|
295
|
+
|
|
296
|
+
const description = candidates[0]?.text.replace(/^About the job\\s*/i, '') || '';
|
|
297
|
+
const applyLink = [...document.querySelectorAll('a[href]')]
|
|
298
|
+
.map(a => ({ href: a.href || '', text: norm(a.textContent || ''), aria: norm(a.getAttribute('aria-label') || '') }))
|
|
299
|
+
.find(a => /apply/i.test(a.text) || /apply/i.test(a.aria));
|
|
300
|
+
|
|
301
|
+
return { description, applyUrl: applyLink?.href || '' };
|
|
302
|
+
})()`);
|
|
303
|
+
enriched.push({
|
|
304
|
+
...job,
|
|
305
|
+
description: normalizeWhitespace(detail?.description),
|
|
306
|
+
apply_url: decodeLinkedinRedirect(String(detail?.applyUrl ?? '')),
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
catch {
|
|
310
|
+
enriched.push({ ...job, description: '', apply_url: '' });
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
return enriched;
|
|
314
|
+
}
|
|
315
|
+
// โโ CLI registration โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
316
|
+
cli({
|
|
317
|
+
site: 'linkedin',
|
|
318
|
+
name: 'search',
|
|
319
|
+
description: 'Search LinkedIn jobs',
|
|
320
|
+
domain: 'www.linkedin.com',
|
|
321
|
+
strategy: Strategy.HEADER,
|
|
322
|
+
browser: true,
|
|
323
|
+
args: [
|
|
324
|
+
{ name: 'query', type: 'string', required: true, help: 'Job search keywords' },
|
|
325
|
+
{ name: 'location', type: 'string', required: false, help: 'Location text such as San Francisco Bay Area' },
|
|
326
|
+
{ name: 'limit', type: 'int', default: 10, help: 'Number of jobs to return (max 100)' },
|
|
327
|
+
{ name: 'start', type: 'int', default: 0, help: 'Result offset for pagination' },
|
|
328
|
+
{ name: 'details', type: 'bool', default: false, help: 'Include full job description and apply URL (slower)' },
|
|
329
|
+
{ name: 'company', type: 'string', required: false, help: 'Comma-separated company names or LinkedIn company IDs' },
|
|
330
|
+
{ name: 'experience_level', type: 'string', required: false, help: 'Comma-separated: internship, entry, associate, mid-senior, director, executive' },
|
|
331
|
+
{ name: 'job_type', type: 'string', required: false, help: 'Comma-separated: full-time, part-time, contract, temporary, volunteer, internship, other' },
|
|
332
|
+
{ name: 'date_posted', type: 'string', required: false, help: 'One of: any, month, week, 24h' },
|
|
333
|
+
{ name: 'remote', type: 'string', required: false, help: 'Comma-separated: on-site, hybrid, remote' },
|
|
334
|
+
],
|
|
335
|
+
columns: ['rank', 'title', 'company', 'location', 'listed', 'salary', 'url'],
|
|
336
|
+
func: async (page, kwargs) => {
|
|
337
|
+
const limit = Math.max(1, Math.min(kwargs.limit ?? 10, 100));
|
|
338
|
+
const start = Math.max(0, kwargs.start ?? 0);
|
|
339
|
+
const includeDetails = Boolean(kwargs.details);
|
|
340
|
+
const location = (kwargs.location ?? '').trim();
|
|
341
|
+
const keywords = String(kwargs.query ?? '').trim();
|
|
342
|
+
if (!keywords)
|
|
343
|
+
throw new Error('query is required');
|
|
344
|
+
const searchParams = new URLSearchParams({ keywords });
|
|
345
|
+
if (location)
|
|
346
|
+
searchParams.set('location', location);
|
|
347
|
+
await page.goto(`https://www.linkedin.com/jobs/search/?${searchParams.toString()}`);
|
|
348
|
+
await page.wait({ text: 'Jobs', timeout: 10 });
|
|
349
|
+
const companyIds = await resolveCompanyIds(page, kwargs.company);
|
|
350
|
+
const input = {
|
|
351
|
+
keywords,
|
|
352
|
+
location,
|
|
353
|
+
limit,
|
|
354
|
+
start,
|
|
355
|
+
companyIds,
|
|
356
|
+
experienceLevels: mapFilterValues(kwargs.experience_level, EXPERIENCE_LEVELS, 'experience_level'),
|
|
357
|
+
jobTypes: mapFilterValues(kwargs.job_type, JOB_TYPES, 'job_type'),
|
|
358
|
+
datePostedValues: mapFilterValues(kwargs.date_posted, DATE_POSTED, 'date_posted'),
|
|
359
|
+
remoteTypes: mapFilterValues(kwargs.remote, REMOTE_TYPES, 'remote'),
|
|
360
|
+
};
|
|
361
|
+
const data = await fetchJobCards(page, input);
|
|
362
|
+
if (!includeDetails)
|
|
363
|
+
return data;
|
|
364
|
+
return enrichJobDetails(page, data);
|
|
365
|
+
},
|
|
366
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|