Add files via upload
This commit is contained in:
parent
d9d1703015
commit
0d678cba92
174
JS/drpy2.js
174
JS/drpy2.js
File diff suppressed because one or more lines are too long
145
JS/drpy2.min.js
vendored
145
JS/drpy2.min.js
vendored
@ -18,6 +18,8 @@ cheerio.jinja2 = function(template, obj) {
|
|||||||
return _jinja2(template, obj)
|
return _jinja2(template, obj)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
let vercode = typeof pdfl === "function" ? "drpy2.1" : "drpy2";
|
||||||
|
const VERSION = vercode + " 3.9.51beta5 20241014";
|
||||||
|
|
||||||
function init_test() {
|
function init_test() {
|
||||||
console.log("init_test_start");
|
console.log("init_test_start");
|
||||||
@ -204,8 +206,6 @@ function pre() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
let rule = {};
|
let rule = {};
|
||||||
let vercode = typeof pdfl === "function" ? "drpy2.1" : "drpy2";
|
|
||||||
const VERSION = vercode + " 3.9.51beta2 20240711";
|
|
||||||
const MOBILE_UA = "Mozilla/5.0 (Linux; Android 11; Pixel 5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.91 Mobile Safari/537.36";
|
const MOBILE_UA = "Mozilla/5.0 (Linux; Android 11; Pixel 5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.91 Mobile Safari/537.36";
|
||||||
const PC_UA = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.54 Safari/537.36";
|
const PC_UA = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.54 Safari/537.36";
|
||||||
const UA = "Mozilla/5.0";
|
const UA = "Mozilla/5.0";
|
||||||
@ -1284,6 +1284,38 @@ function keysToLowerCase(obj) {
|
|||||||
}, {})
|
}, {})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function parseQueryString(query) {
|
||||||
|
const params = {};
|
||||||
|
query.split("&").forEach(function(part) {
|
||||||
|
const regex = /^(.*?)=(.*)/;
|
||||||
|
const match = part.match(regex);
|
||||||
|
if (match) {
|
||||||
|
const key = decodeURIComponent(match[1]);
|
||||||
|
const value = decodeURIComponent(match[2]);
|
||||||
|
params[key] = value
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return params
|
||||||
|
}
|
||||||
|
|
||||||
|
function encodeIfContainsSpecialChars(value) {
|
||||||
|
const specialChars = ":/?#[]@!$'()*+,;=%";
|
||||||
|
if (specialChars.split("").some(char => value.includes(char))) {
|
||||||
|
return encodeURIComponent(value)
|
||||||
|
}
|
||||||
|
return value
|
||||||
|
}
|
||||||
|
|
||||||
|
function objectToQueryString(obj) {
|
||||||
|
const encoded = [];
|
||||||
|
for (let key in obj) {
|
||||||
|
if (obj.hasOwnProperty(key)) {
|
||||||
|
encoded.push(encodeURIComponent(key) + "=" + encodeIfContainsSpecialChars(obj[key]))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return encoded.join("&")
|
||||||
|
}
|
||||||
|
|
||||||
function request(url, obj, ocr_flag) {
|
function request(url, obj, ocr_flag) {
|
||||||
ocr_flag = ocr_flag || false;
|
ocr_flag = ocr_flag || false;
|
||||||
if (typeof obj === "undefined" || !obj || obj === {}) {
|
if (typeof obj === "undefined" || !obj || obj === {}) {
|
||||||
@ -1343,6 +1375,14 @@ function request(url, obj, ocr_flag) {
|
|||||||
if (obj.redirect === false) {
|
if (obj.redirect === false) {
|
||||||
obj.redirect = 0
|
obj.redirect = 0
|
||||||
}
|
}
|
||||||
|
if (obj.headers.hasOwnProperty("Content-Type") || obj.headers.hasOwnProperty("content-type")) {
|
||||||
|
if (obj.headers["Content-Type"].includes("application/x-www-form-urlencoded")) {
|
||||||
|
log("body");
|
||||||
|
if (typeof obj.body == "string") {
|
||||||
|
let temp_obj = parseQueryString(obj.body)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
console.log(JSON.stringify(obj.headers));
|
console.log(JSON.stringify(obj.headers));
|
||||||
console.log("request:" + url + `|method:${obj.method||"GET"}|body:${obj.body||""}`);
|
console.log("request:" + url + `|method:${obj.method||"GET"}|body:${obj.body||""}`);
|
||||||
let res = req(url, obj);
|
let res = req(url, obj);
|
||||||
@ -2551,8 +2591,12 @@ function init(ext) {
|
|||||||
if (typeof ext == "object") {
|
if (typeof ext == "object") {
|
||||||
rule = ext
|
rule = ext
|
||||||
} else if (typeof ext == "string") {
|
} else if (typeof ext == "string") {
|
||||||
if (ext.startsWith("http") || ext.startsWith("file://")) {
|
let is_file = ext.startsWith("file://");
|
||||||
|
if (ext.startsWith("http") || is_file) {
|
||||||
let query = getQuery(ext);
|
let query = getQuery(ext);
|
||||||
|
if (is_file) {
|
||||||
|
ext = ext.split("?")[0]
|
||||||
|
}
|
||||||
let js = request(ext, {
|
let js = request(ext, {
|
||||||
method: "GET"
|
method: "GET"
|
||||||
});
|
});
|
||||||
@ -2561,7 +2605,11 @@ function init(ext) {
|
|||||||
eval("(function(){" + js.replace("var rule", "rule") + "})()")
|
eval("(function(){" + js.replace("var rule", "rule") + "})()")
|
||||||
}
|
}
|
||||||
if (query.type === "url" && query.params) {
|
if (query.type === "url" && query.params) {
|
||||||
rule.params = urljoin(ext, query.params)
|
if (is_file && /^http/.test(query.params)) {
|
||||||
|
rule.params = query.params
|
||||||
|
} else {
|
||||||
|
rule.params = urljoin(ext, query.params)
|
||||||
|
}
|
||||||
} else if (query.params) {
|
} else if (query.params) {
|
||||||
rule.params = query.params
|
rule.params = query.params
|
||||||
}
|
}
|
||||||
@ -2699,13 +2747,15 @@ function init(ext) {
|
|||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(`处理headers发生错误:${e.message}`)
|
console.log(`处理headers发生错误:${e.message}`)
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
rule.headers = {}
|
||||||
}
|
}
|
||||||
|
oheaders = deepCopy(rule.headers);
|
||||||
rule_fetch_params = {
|
rule_fetch_params = {
|
||||||
headers: rule.headers || false,
|
headers: rule.headers,
|
||||||
timeout: rule.timeout,
|
timeout: rule.timeout,
|
||||||
encoding: rule.encoding
|
encoding: rule.encoding
|
||||||
};
|
};
|
||||||
oheaders = rule.headers || {};
|
|
||||||
RKEY = typeof key !== "undefined" && key ? key : "drpy_" + (rule.title || rule.host);
|
RKEY = typeof key !== "undefined" && key ? key : "drpy_" + (rule.title || rule.host);
|
||||||
pre();
|
pre();
|
||||||
init_test()
|
init_test()
|
||||||
@ -2867,6 +2917,89 @@ function getRule(key) {
|
|||||||
return key ? rule[key] || "" : rule
|
return key ? rule[key] || "" : rule
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function deepCopy(_obj) {
|
||||||
|
return JSON.parse(JSON.stringify(_obj))
|
||||||
|
}
|
||||||
|
|
||||||
|
function matchesAll(str, pattern, flatten) {
|
||||||
|
if (!pattern.global) {
|
||||||
|
pattern = new RegExp(pattern.source, "g" + (pattern.ignoreCase ? "i" : "") + (pattern.multiline ? "m" : ""))
|
||||||
|
}
|
||||||
|
var matches = [];
|
||||||
|
var match;
|
||||||
|
while ((match = pattern.exec(str)) !== null) {
|
||||||
|
matches.push(match)
|
||||||
|
}
|
||||||
|
return flatten ? matches.flat() : matches
|
||||||
|
}
|
||||||
|
|
||||||
|
function stringUtils() {
|
||||||
|
Object.defineProperties(String.prototype, {
|
||||||
|
replaceX: {
|
||||||
|
value: function(regex, replacement) {
|
||||||
|
let matches = matchesAll(this, regex, true);
|
||||||
|
if (matches && matches.length > 1) {
|
||||||
|
const hasCaptureGroup = /\$\d/.test(replacement);
|
||||||
|
if (hasCaptureGroup) {
|
||||||
|
return this.replace(regex, m => m.replace(regex, replacement))
|
||||||
|
} else {
|
||||||
|
return this.replace(regex, (m, p1) => m.replace(p1, replacement))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return this.replace(regex, replacement)
|
||||||
|
},
|
||||||
|
configurable: true,
|
||||||
|
enumerable: false,
|
||||||
|
writable: true
|
||||||
|
},
|
||||||
|
parseX: {
|
||||||
|
get: function() {
|
||||||
|
try {
|
||||||
|
return JSON.parse(this)
|
||||||
|
} catch (e) {
|
||||||
|
console.log(e.message);
|
||||||
|
return this.startsWith("[") ? [] : {}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
configurable: true,
|
||||||
|
enumerable: false
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function cut(text, start, end, method, All) {
|
||||||
|
let result = "";
|
||||||
|
let c = (t, s, e) => {
|
||||||
|
let result = "";
|
||||||
|
let rs = [];
|
||||||
|
let results = [];
|
||||||
|
try {
|
||||||
|
let lr = new RegExp(String.raw`${s}`.toString());
|
||||||
|
let rr = new RegExp(String.raw`${e}`.toString());
|
||||||
|
const segments = t.split(lr);
|
||||||
|
if (segments.length < 2) return "";
|
||||||
|
let cutSegments = segments.slice(1).map(segment => {
|
||||||
|
let splitSegment = segment.split(rr);
|
||||||
|
return splitSegment.length < 2 ? undefined : splitSegment[0] + e
|
||||||
|
}).filter(f => f);
|
||||||
|
if (All) {
|
||||||
|
return `[${cutSegments.join(",")}]`
|
||||||
|
} else {
|
||||||
|
return cutSegments[0]
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.log(`Error cutting text:${e.message}`)
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
};
|
||||||
|
result = c(text, start, end);
|
||||||
|
stringUtils();
|
||||||
|
if (method && typeof method === "function") {
|
||||||
|
result = method(result)
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
function DRPY() {
|
function DRPY() {
|
||||||
return {
|
return {
|
||||||
runMain: runMain,
|
runMain: runMain,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user