-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathset-tags.js
More file actions
178 lines (160 loc) · 6.04 KB
/
Copy pathset-tags.js
File metadata and controls
178 lines (160 loc) · 6.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/**
* play-console set-tags
*
* Set app tags in Google Play Console Store settings.
* Supports up to 5 tags selected from Play Console's predefined tag list.
* This field is NOT accessible via the Google Play Developer API.
*/
import { cli, Strategy } from '@jackwener/opencli/registry';
import { appUrl, waitForPlayConsole, clickSave } from './_shared.js';
cli({
site: 'play-console',
name: 'set-tags',
description: 'Set app tags in Store settings — up to 5 tags (NOT available via Developer API)',
domain: 'play.google.com',
strategy: Strategy.UI,
args: [
{
name: 'dev_id',
required: true,
positional: true,
help: 'Developer account ID (numeric)',
},
{
name: 'app_id',
required: true,
positional: true,
help: 'App ID (numeric)',
},
{
name: 'tags',
required: true,
help: 'Comma-separated list of tags to set (max 5), e.g. "productivity,offline,note-taking". Tags are searched by keyword.',
},
{
name: 'replace',
type: 'bool',
default: true,
help: 'If true (default), clear existing tags first. If false, add tags to existing ones.',
},
{
name: 'acc_idx',
type: 'int',
default: 0,
help: 'Google account index (default: 0)',
},
],
columns: ['success', 'tags_set', 'tags_failed', 'message'],
func: async (page, kwargs) => {
const { dev_id, app_id, tags, replace, acc_idx } = kwargs;
const tagList = String(tags).split(',').map(t => t.trim()).filter(Boolean);
if (tagList.length === 0) throw new Error('No tags provided');
if (tagList.length > 5) throw new Error('Maximum 5 tags allowed');
const targetUrl = appUrl(String(dev_id), String(app_id), 'store-presence/store-settings', Number(acc_idx));
await page.goto(targetUrl, { waitUntil: 'networkidle' });
await waitForPlayConsole(page);
// Step 1: Clear existing tags if replace=true
if (replace) {
const cleared = await page.evaluate(() => {
// Play Console tag chips have a remove button (×)
const removeButtons = Array.from(document.querySelectorAll(
'mat-chip .mat-chip-remove, mat-chip button[aria-label*="remove"], ' +
'gpc-chip .remove-btn, [class*="tag"] button[aria-label*="remove"], ' +
'.selected-tags mat-chip-row button'
));
removeButtons.forEach(btn => btn.click());
return removeButtons.length;
});
if (cleared > 0) await page.waitForTimeout(500);
}
// Step 2: Add each tag
const tagsSet = [];
const tagsFailed = [];
for (const tag of tagList) {
// Find the tag input / autocomplete field
const inputFound = await page.evaluate((tagQuery) => {
const tagInputSelectors = [
'input[placeholder*="tag"]',
'input[placeholder*="Tag"]',
'input[placeholder*="Add tag"]',
'gpc-tag-input input',
'.tag-input input',
'mat-chip-grid input',
'mat-chip-list input',
];
for (const sel of tagInputSelectors) {
const input = document.querySelector(sel);
if (input && input.offsetParent !== null) {
input.focus();
const nativeInputValueSetter = Object.getOwnPropertyDescriptor(
window.HTMLInputElement.prototype, 'value'
).set;
nativeInputValueSetter.call(input, tagQuery);
input.dispatchEvent(new Event('input', { bubbles: true }));
return { found: true, selector: sel };
}
}
return { found: false };
}, tag);
if (!inputFound.found) {
tagsFailed.push(`${tag} (input not found)`);
continue;
}
// Wait for autocomplete suggestions
try {
await page.waitForSelector(
'mat-option, .mat-option, .autocomplete-option, [role="option"]',
{ timeout: 3000 }
);
} catch {
tagsFailed.push(`${tag} (no suggestions appeared)`);
continue;
}
await page.waitForTimeout(300);
// Click the best matching option
const optionClicked = await page.evaluate((tagQuery) => {
const options = Array.from(document.querySelectorAll(
'mat-option, .mat-option, [role="option"]'
));
const tagLower = tagQuery.toLowerCase();
// Exact match first
const exact = options.find(o => o.textContent?.trim().toLowerCase() === tagLower);
if (exact) { exact.click(); return { clicked: true, text: exact.textContent?.trim() }; }
// Partial match
const partial = options.find(o => o.textContent?.trim().toLowerCase().includes(tagLower));
if (partial) { partial.click(); return { clicked: true, text: partial.textContent?.trim() }; }
// First option as fallback
if (options[0]) {
options[0].click();
return { clicked: true, text: options[0].textContent?.trim(), fallback: true };
}
return { clicked: false, available: options.map(o => o.textContent?.trim()).slice(0, 10) };
}, tag);
if (!optionClicked.clicked) {
tagsFailed.push(`${tag} (not in suggestions: ${optionClicked.available?.join(', ')})`);
// Close the dropdown
await page.keyboard.press('Escape');
} else {
const displayText = optionClicked.text || tag;
tagsSet.push(optionClicked.fallback ? `${tag}→${displayText}` : displayText);
}
await page.waitForTimeout(400);
}
if (tagsSet.length === 0) {
throw new Error(
`No tags were set. Failed: ${tagsFailed.join('; ')}. ` +
'Tags must match Play Console\'s predefined tag list. ' +
'Try browsing to Store settings in Play Console to see available tags.'
);
}
await clickSave(page);
return [{
success: tagsFailed.length === 0,
tags_set: tagsSet.join(', '),
tags_failed: tagsFailed.join(', ') || '—',
message: tagsFailed.length === 0
? `All ${tagsSet.length} tag(s) saved successfully`
: `${tagsSet.length} tag(s) saved, ${tagsFailed.length} failed`,
}];
},
});