适配chrome

This commit is contained in:
jenkins 2025-05-12 09:52:31 +08:00
parent ac1f86b0c8
commit f895ec6aa4
10 changed files with 71 additions and 24 deletions

View File

@ -1,10 +1,10 @@
/********************************************************************** /**********************************************************************
@see https://www.testleaf.com @see https://gitea.kiki.kim/HA/rutoxpath
@since - 2019 @since - 2019
***********************************************************************/ ***********************************************************************/
let installURL = "https://sites.google.com/testleaf.com/ruto/"; let installURL = "https://gitea.kiki.kim/HA/rutoxpath";
let updateURL = "https://sites.google.com/testleaf.com/ruto/videos" let updateURL = "https://gitea.kiki.kim/HA/rutoxpath"
let uninstallURL = "https://sites.google.com/testleaf.com/ruto/download/uninstall"; let uninstallURL = "https://gitea.kiki.kim/HA/rutoxpath";
const manifest = chrome.runtime.getManifest(); const manifest = chrome.runtime.getManifest();
//TODO: Enable it before release //TODO: Enable it before release
@ -23,7 +23,7 @@ const installedListener = (details) => {
function onClickNoti() { chrome.tabs.create({ url: updateURL }) } function onClickNoti() { chrome.tabs.create({ url: updateURL }) }
const updateNotification = () => { const updateNotification = () => {
chrome.notifications.create({ chrome.notifications.create({
title: `Ruto`, title: `RXPath`,
message: `Click here to see the changelog of version ${manifest.version}`, message: `Click here to see the changelog of version ${manifest.version}`,
type: 'basic', type: 'basic',
iconUrl: 'logo/128.png' iconUrl: 'logo/128.png'
@ -31,8 +31,8 @@ const updateNotification = () => {
} }
const installNotification = () => { const installNotification = () => {
chrome.notifications.create('onInstalled', { chrome.notifications.create('onInstalled', {
title: `Ruto`, title: `RXPath`,
message: `Please restart your browser to use Ruto`, message: `Please restart your browser to use RXPath`,
type: 'basic', type: 'basic',
iconUrl: 'logo/128.png' iconUrl: 'logo/128.png'
}); });

View File

@ -1,6 +1,6 @@
// version 3.1.0 id = ilcoelkkcokgeeijnopjnolmmighnppp // version 3.1.0 id = ilcoelkkcokgeeijnopjnolmmighnppp
/*** /***
* @see https://www.testleaf.com * @see https://gitea.kiki.kim/HA/rutoxpath
* @since - 2019 - Feb * @since - 2019 - Feb
*/ */
"use strict"; "use strict";
@ -402,12 +402,17 @@ rutoX.buildXpath = (element, boolAnchor) => {
hasFrame = frameElement != null ? frameElement : null; hasFrame = frameElement != null ? frameElement : null;
let attributeElement = element.attributes; let attributeElement = element.attributes;
let preiousSiblingElement = element.previousElementSibling; let preiousSiblingElement = element.previousElementSibling;
let childrenElement = element.childNodes;
try { try {
xpathAttributes(attributeElement, tagName, element); xpathAttributes(attributeElement, tagName, element);
} catch (e) { } } catch (e) { }
try { try {
xpathFollowingSibling(preiousSiblingElement, tagName); xpathFollowingSibling(preiousSiblingElement, tagName); //获取前一个兄弟节点的元素,然后定位当前的位置
} catch (e) { }
try {
xpathChildren(childrenElement, tagName); //获取子节点
} catch (e) { } } catch (e) { }
try { try {
@ -1067,6 +1072,11 @@ function xpathFollowingSibling(preiousSiblingElement, tagName) {
addPreviousSibling(preiousSiblingElement, tagName); addPreviousSibling(preiousSiblingElement, tagName);
} }
} }
function xpathChildren(childrenElement, tagName) {
if (childrenElement != null || childrenElement != undefined) {
addChildren(childrenElement, tagName);
}
}
function removeTunaXpath(element) { function removeTunaXpath(element) {
element.removeAttribute('rutoxpath', 'ruto'); element.removeAttribute('rutoxpath', 'ruto');
} }
@ -1178,6 +1188,35 @@ function getLabel(node, tagName) {
} }
} }
} }
function addChildren(preSib, tagName) {
try {
Object.values(preSib).forEach(value => {
console.log(value);
if (!(filterAttributesFromElement(item))) {
let tempvalue = null;
switch (item.name) {
case 'id':
if (preSib.hasAttribute('id')) {
let id = preSib.id;
let re = new RegExp('\\d{' + maxId + ',}', '\g');
let matches = re.test(id);
if ((id != null) && (id.length > 0) && matches == false) {
tempvalue = id;
}
}
xpathArray.push([2, 'Children based XPath', tempvalue]);
break;
case 'robotid':
tempvalue = item.value
xpathArray.push([2, 'Children based XPath', tempvalue]);
break;
}
}
});
}
catch (error) { }
}
function addPreviousSibling(preSib, tagName) { function addPreviousSibling(preSib, tagName) {
try { try {
let classHasSpace = false; let classHasSpace = false;
@ -1197,6 +1236,9 @@ function addPreviousSibling(preSib, tagName) {
} }
} }
break; break;
case 'robotid':
tempvalue = item.value
break;
case 'class': case 'class':
if (preSib.hasAttribute('class')) { if (preSib.hasAttribute('class')) {
tempvalue = preSib.className; tempvalue = preSib.className;

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.1 KiB

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 235 B

After

Width:  |  Height:  |  Size: 250 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 404 B

After

Width:  |  Height:  |  Size: 851 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.7 KiB

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.9 KiB

After

Width:  |  Height:  |  Size: 85 KiB

View File

@ -1,13 +1,13 @@
{ {
"update_url": "https://clients2.google.com/service/update2/crx", "update_url": "https://gitea.kiki.kim/HA/rutoxpath/release",
"name": "Ruto - XPath Finder", "name": "RXPath Finder",
"short_name": "Ruto", "short_name": "RXPath",
"manifest_version": 2, "manifest_version": 2,
"version": "7.0.1", "version": "1.0.1",
"content_security_policy": "script-src 'self'; object-src 'self'", "content_security_policy": "script-src 'self'; object-src 'self'",
"description": "Ruto brings the best XPath to you. We are striving hard to improve better performance and more new features", "description": "基于Rūto-XPath Finder 7.0.1版本的二次开发,仅个人学习使用。",
"homepage_url": "https://sites.google.com/testleaf.com/ruto/", "homepage_url": "https://gitea.kiki.kim/HA/rutoxpath",
"commands": { "commands": {
"_execute_browser_action": { "_execute_browser_action": {
"suggested_key": { "suggested_key": {
@ -59,7 +59,7 @@
"128": "logo/128.png" "128": "logo/128.png"
}, },
"browser_action": { "browser_action": {
"default_title": "Ruto offered by TestLeaf", "default_title": "RXPath",
"default_popup": "popup.html" "default_popup": "popup.html"
}, },
"options_page": "option.html", "options_page": "option.html",

View File

@ -14,8 +14,9 @@
<body id="body"> <body id="body">
<div id="version" class="flex-containers"> <div id="version" class="flex-containers">
<p>开启后点击页面元素即可获取Xpath信息</p>
<div class="onoffswitch" data-balloon-length="large" <div class="onoffswitch" data-balloon-length="large"
data-balloon="Use only when right click in not available in pages. Get XPath in a single click. Note: Default click action will be disabled in pages, turn off to use regular click action." data-balloon="开启后点击对象即可获取Xpath同时原页面的点击动作失效。"
data-balloon-pos="right"> data-balloon-pos="right">
<input type="checkbox" name="onoffswitch" class="onoffswitch-checkbox" id="myonoffswitch" /> <input type="checkbox" name="onoffswitch" class="onoffswitch-checkbox" id="myonoffswitch" />
<label class="onoffswitch-label" for="myonoffswitch"> <label class="onoffswitch-label" for="myonoffswitch">
@ -27,10 +28,10 @@
<img src="./logo/icon/controls.svg" alt="Setting" /> <img src="./logo/icon/controls.svg" alt="Setting" />
</div> </div>
<div class="likediv" data-balloon-length="small" data-balloon="leave a review" data-balloon-pos="left"> <div class="likediv" data-balloon-length="small" data-balloon="leave a review" data-balloon-pos="left">
<a href="https://chrome.google.com/webstore/detail/ruto-xpath-finder/ilcoelkkcokgeeijnopjnolmmighnppp/reviews" <!-- <a href="https://chrome.google.com/webstore/detail/ruto-xpath-finder/ilcoelkkcokgeeijnopjnolmmighnppp/reviews"
target="_blank"> target="_blank">
<img src="./logo/icon/love.svg" alt="review" /> <img src="./logo/icon/love.svg" alt="review" />
</a> </a> -->
</div> </div>
</div> </div>
<hr /> <hr />
@ -76,11 +77,14 @@
<hr /> <hr />
<div class="logos"> <div class="logos">
<div class="flex" data-balloon="Home" data-balloon-pos="right"> <div class="flex" data-balloon="Home" data-balloon-pos="right">
<a href="https://sites.google.com/testleaf.com/ruto/" target="_blank"> <a href="https://gitea.kiki.kim/HA/rutoxpath" target="_blank">
<img src="logo/ruto.webp" alt="Ruto" style="width: 80px;" class="rutohome" /> <img src="logo/ruto.webp" alt="Ruto" style="width: 90px;height: 50px;" class="rutohome" />
</a> </a>
</div> </div>
<div class="record" id="startRecord"> <div class="record" id="startRecord">
<div>
<p style="font-size:0.6em; color:#888; margin-top:0.8em">Powered by Rūto-XPath Finder 7.0.1</p>
</div>
<div class="onoffswitch"> <div class="onoffswitch">
<input type="checkbox" name="onoffswitchRecord" class="onoffswitch-checkbox" id="recordIcon" /> <input type="checkbox" name="onoffswitchRecord" class="onoffswitch-checkbox" id="recordIcon" />
<label class="onoffswitch-label" for="recordIcon"> <label class="onoffswitch-label" for="recordIcon">
@ -90,8 +94,8 @@
</div> </div>
</div> </div>
<div class="flex"> <div class="flex">
<a href="https://testleaf.com" target="_blank"> <a href="https://kiki.kim/" target="_blank">
<img src="logo/tl.webp" alt="logo" style="width: 80px;" /> <img src="logo/tl.webp" alt="logo" style="width: 80px;height: 50px;" />
</a> </a>
</div> </div>
</div> </div>

View File

@ -837,7 +837,8 @@ function addPreviousSibling(preSib, tagName) {
case 'robotid': case 'robotid':
if (preSib.hasAttribute('robotid')) { if (preSib.hasAttribute('robotid')) {
tempvalue = item.value tempvalue = item.value
xpathArray.push([2, 'Following sibling based RobotId:', tempvalue]) // 这个获取的是前一个兄弟节点的元素
// xpathArray.push([2, 'Following sibling based RobotId:', tempvalue])
} }
break; break;
case 'class': case 'class':