MCPcopy Create free account
hub / github.com/ChinaGodMan/UserScripts / getScriptsInfo

Function getScriptsInfo

script-finder-plus/script-finder-plus.user.js:221–271  ·  view source on GitHub ↗
(domain, page = 1)

Source from the content-addressed store, hash-verified

219 let loadedPages = 0
220
221 function getScriptsInfo(domain, page = 1) {
222 var url = `https://greasyfork.org/scripts/by-site/${domain}?filter_locale=0&sort=updated&page=${page}`
223
224 GM_xmlhttpRequest({
225 method: 'GET',
226 url: url,
227 onload: (response) => {
228 // 解析结果
229 const parser = new DOMParser()
230 const doc = parser.parseFromString(response.responseText, 'text/html')
231 const scripts = doc.querySelector('#browse-script-list')?.querySelectorAll('[data-script-id]')
232 let scriptsInfo = []
233
234 if (!scripts) {
235 scriptsInfo = errorMessage
236 } else {
237 for (var i = 0; i < scripts.length; i++) {
238 scriptsInfo.push(parseScriptInfo(scripts[i]))
239 }
240 }
241
242 // 处理对象
243 const loadMoreButton = document.querySelector('.sf-load-more')
244 console.log(doc.querySelector('.next_page'))
245 if (doc.querySelector('.next_page') == null || doc.querySelector('.next_page')?.getAttribute('aria-disabled') === 'true') {
246 loadedPages = 'max'
247 loadMoreButton.disabled = true
248 loadMoreButton.textContent = translate('AllScriptsLoaded')
249 } else {
250 loadMoreButton.disabled = false
251 loadMoreButton.textContent = translate('LoadMore')
252 }
253 // console.log(scriptsInfo);
254 document.querySelector('.sf-wait-loading').style.display = 'none'
255 loadMoreButton.style.display = 'block'
256 appendScriptsInfo(scriptsInfo)
257 updateMatches()
258
259 loadedPages = typeof loadedPages === 'number' ? loadedPages + 1 : 0
260 // console.log(loadedPages)
261 },
262 onerror: () => {
263 console.log('Some error occurred!')
264 if (loadedPages === 0) {
265 appendScriptsInfo(scriptsInfo)
266 }
267 const scriptsInfo = errorMessage
268 document.querySelector('.sf-wait-loading').style.display = 'none'
269 }
270 })
271 }
272
273 // 解析脚本信息
274 function parseScriptInfo(script) {

Callers 1

setupUIFunction · 0.85

Calls 3

parseScriptInfoFunction · 0.85
appendScriptsInfoFunction · 0.85
updateMatchesFunction · 0.85

Tested by

no test coverage detected