在Google Play订单历史上过滤$ 0.00值

发布于 2025-02-06 22:50:58 字数 943 浏览 2 评论 0原文

我想在Google Play上检查旧购买,但是历史将显示一切我声称。包括大量免费应用程序(列出为$ 0.00),并且不可能过滤该列表中的任何内容。

因此,我认为我可以制作一个简单的TampermonKey脚本来为我做,但由于某种原因无法工作。
我在这里想念什么?谢谢。

这是我到目前为止得到的:

// ==UserScript==
// @name         Filter Out $0.00 Garbage
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  ...
// @author       Me
// @match        https://play.google.com/store/account/orderhistory
// @icon         https://www.google.com/s2/favicons?sz=64&domain=google.com
// @grant        none
// ==/UserScript==

(function() {
  var ele = document.getElementsByClassName('mshXob');
  for (var i = 0; i < ele.length; ++i) {
    var item = ele[i];
    if (item.innerHTML == '$0.00') {
      var gp = item.parentNode.parentNode.parentNode;
      gp.style.display = 'none';
    }
  }
})();

I wanted to check an old purchase on Google Play, but the history will show everything that I claimed. Including, a ton of free apps (listed as $0.00), and it's impossible to filter anything in that list.

So I thought I could make a simple TamperMonkey script to do it for me, but it's not working for some reason.
What am I missing here? Thanks.

Here's what I got so far:

// ==UserScript==
// @name         Filter Out $0.00 Garbage
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  ...
// @author       Me
// @match        https://play.google.com/store/account/orderhistory
// @icon         https://www.google.com/s2/favicons?sz=64&domain=google.com
// @grant        none
// ==/UserScript==

(function() {
  var ele = document.getElementsByClassName('mshXob');
  for (var i = 0; i < ele.length; ++i) {
    var item = ele[i];
    if (item.innerHTML == '$0.00') {
      var gp = item.parentNode.parentNode.parentNode;
      gp.style.display = 'none';
    }
  }
})();

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

隐诗 2025-02-13 22:50:58

也许在此处使用XPATH尝试一下

// ==UserScript==
// @name         Filter Out $0.00 Garbage
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  ...
// @author       Me
// @match        https://play.google.com/store/account/orderhistory*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=google.com
// @grant        none
// ==/UserScript==

(function() {
    const MutationObserver = window.MutationObserver || window.WebKitMutationObserver;
    const observer = new MutationObserver(hideZeroElements);
    // tried with div elements but does not seem to work.
    observer.observe(document.body, {
        subtree: true,
        childList: true,
        attributes: false
    });
})();

function hideZeroElements(mutations, observer) {
  /**
  * Get all the divs whom grand children contain a 0,00 value or 0.00 in your case
  */
  const history = document.evaluate('//div[div[2]/div//div[contains(text(), "0.00")]]', document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
  /**
  * Loop over all the elements found and hide them.
  */
  for ( let i = 0; i < history.snapshotLength; i++) {
      history.snapshotItem(i).style.display = "none";
  }
}

Note :我不确定是否有一种方法可以断开观察者在Userscript中的连接。

Maybe try it out with XPATH

Here:

// ==UserScript==
// @name         Filter Out $0.00 Garbage
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  ...
// @author       Me
// @match        https://play.google.com/store/account/orderhistory*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=google.com
// @grant        none
// ==/UserScript==

(function() {
    const MutationObserver = window.MutationObserver || window.WebKitMutationObserver;
    const observer = new MutationObserver(hideZeroElements);
    // tried with div elements but does not seem to work.
    observer.observe(document.body, {
        subtree: true,
        childList: true,
        attributes: false
    });
})();

function hideZeroElements(mutations, observer) {
  /**
  * Get all the divs whom grand children contain a 0,00 value or 0.00 in your case
  */
  const history = document.evaluate('//div[div[2]/div//div[contains(text(), "0.00")]]', document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
  /**
  * Loop over all the elements found and hide them.
  */
  for ( let i = 0; i < history.snapshotLength; i++) {
      history.snapshotItem(i).style.display = "none";
  }
}

Note: I'm not sure if there is a way to disconnect the observer or not inside the userscript.

不一样的天空 2025-02-13 22:50:58

您可能依靠更改的类名称。 JavaScript库(例如Angular/React/etc)可能会将ID和类名称更改为混淆代码。

尝试使用不依赖恒定ID和类名的DOM选择器和DOM遍历方法。

尝试以下操作:

// ==UserScript==
// @name         play.google.com/store/account/orderhistory
// @namespace    http://tampermonkey.net/
// @match        https://play.google.com/store/account/orderhistory
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
    const container = document.querySelector('body>c-wiz:nth-child(5)>div>div>div:nth-child(3)+div>div:nth-child(1)');
    const orders = container.querySelectorAll('div');
    orders.forEach((el,_) => {
        const bucks = el.querySelector('div:nth-child(2)>div>div:nth-child(2)');
        if (bucks !== null){
            if (bucks.innerText === 'US$0.00') el.remove();
        }
    });

})();

You may be relying on classNames that change. JavaScript libraries like Angular/React/etc may change IDs and ClassNames to obfuscate code.

Try using DOM selectors and DOM traversal methods that do not rely on constant ID and class names.

Try this:

// ==UserScript==
// @name         play.google.com/store/account/orderhistory
// @namespace    http://tampermonkey.net/
// @match        https://play.google.com/store/account/orderhistory
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
    const container = document.querySelector('body>c-wiz:nth-child(5)>div>div>div:nth-child(3)+div>div:nth-child(1)');
    const orders = container.querySelectorAll('div');
    orders.forEach((el,_) => {
        const bucks = el.querySelector('div:nth-child(2)>div>div:nth-child(2)');
        if (bucks !== null){
            if (bucks.innerText === 'US$0.00') el.remove();
        }
    });

})();

紅太極 2025-02-13 22:50:58

这是另一个答复您的评论(由于需要更多的灵活性而无法回答)

访问该页面时,TM图标会得到红点吗?如果是这样,脚本正在运行但不起作用;如果没有,@Match行没有触发脚本(即与URL不匹配)。您能确定哪种情况吗?

接下来要检查:打开DevTools(F12)并在第一个QuerySelector中粘贴。 devtools是否显示这样的内容(DevTools正在使用div.ngftbf.fny74c

“

”行,可能有必要调整选择器。做到这一点的方法是逐步构建选择器,并查看添加每个阶段时会发生什么:

document.querySelector('body')  //this HAS to return something...!

然后:

document.querySelector('body>c-wiz:nth-child(5)')

noreferrer“> (3)</code - 也尝试)

在每个阶段,Chrome DevTools应该显示一些东西。例如:

“在此处输入图像描述”

您可能会发现此视频很有帮助: https> https:https: //www.youtube.com/watch?v=sowajlx1uka

让我知道您所看到的。

Here is another answer responding to your comment (could not respond with a comment because more flexibility required).

Does the TM icon get a red dot when you visit that page? If so, the script is running but not working; if not, the @match line is not triggering the script (i.e. does not match the url). Can you determine which is the case?

Next thing to check: open DevTools (F12) and paste in the first querySelector. Does DevTools show anything like this (DevTools is responding with div.NgfTBf.fny74c):

enter image description here

If nothing appears when you paste-in that querySelector line, it might be necessary to tweak that selector. The way to do that is to build-up the selector bit-by-bit and see what happens as each stage is added:

document.querySelector('body')  //this HAS to return something...!

enter image description here

then:

document.querySelector('body>c-wiz:nth-child(5)')

(that one might need to be nth-child(3) - try that also)

At each stage, Chrome DevTools should show something. For example:

enter image description here

You might find this video to be helpful: https://www.youtube.com/watch?v=SowaJlX1uKA

Let me know what you see.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文