Tampermonkey,[Google搜索结果]交换网站标题和链接网址

问题描述 投票:0回答:1

这是Google搜索结果代码,我想将元素移动到href容器中。在这种情况下,交换第一个div.TbwUpd和最后一个h3.LC20lb。所以这个:

<div class="g">
    <div data-hveid="CAMQAA" data-ved="2ahUKEwiy1bOI8IPlAhWVMN4KHfE2DXcQFSgAMAt6BAgDEAA">
        <div class "rc">
            <div class "r"> 
                <a href="https://www.merriam-webster.com/dictionary/meh" onmousedown="return>
                    <div class="TbwUpd">
                        <img class="xA33Gc" alt="https://www.merriam-webster.com/" height="16" src="data:image/png;base64,I=" width="16" data-atf="3"><cite class="iUh30 bc rpCHfe">Merriam-Webster › dictionary › meh</cite></div>
                    <br>
                    <h3 class="LC20lb">
                        <div class="ellip">Meh | Definition of Meh by Merriam-Webster</div></h3>
                </a>
            </div>
        </div>
    </div>
</div>

进入

<div class="g">
    <div data-hveid="CAMQAA" data-ved="2ahUKEwiy1bOI8IPlAhWVMN4KHfE2DXcQFSgAMAt6BAgDEAA">
        <div class "rc">
            <div class "r"> 
                <a href="https://www.merriam-webster.com/dictionary/meh" onmousedown="return>
                    <h3 class="LC20lb">
                        <div class="ellip">Meh | Definition of Meh by Merriam-Webster</div></h3>
                    <br>
                    <div class="TbwUpd">
                        <img class="xA33Gc" alt="https://www.merriam-webster.com/" height="16" src="data:image/png;base64,I=" width="16" data-atf="3"><cite class="iUh30 bc rpCHfe">Merriam-Webster › dictionary › meh</cite></div>
                </a>
            </div>
        </div>
    </div>
</div>

我尝试构建代码,但无法正常工作

// ==UserScript==
// @name        Rearrange Goggle Search result :Swap Title and URL
// @include     https://www.google.com/search*
// @version     1
// @grant       none
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js
// ==/UserScript==

$('.TbwUpd').appendTo('.LC20lb');

original

After swap elements

jquery html greasemonkey tampermonkey userscripts
1个回答
0
投票

1- Google结果是动态创建的,因此,在这种情况下,需要大量其他代码来查找动态更改2-无需为一个很小的代码添加一个700+函数长的JQuery。这将比纯JavaScript效率更高。 (注意:不建议使用JQuery 1和2,因为它们有问题,应避免使用)3-我猜想有不止一项要查找和更改,因此fowling代码将找到所有这些]

© www.soinside.com 2019 - 2024. All rights reserved.