2010-09-10 69 views
1

我必須從很多頁面複製並粘貼輸入類型=「按鈕」(即值=「1.25」,值=「3.50」)的值。是否有可能使用jquery或greasemonkey?如何從輸入類型=「按鈕」複製和粘貼值?

<td> 
    <input type="button" onmouseout="btnGiocataOut(this)" onmouseover="btnGiocataOver(this)" onclick="aggiungiScommessa(6659, 12, 22, 1, 125)" value="1.25" class="ris"> 
</td> 
<td class="valore" colspan="1">Over</td> 
<td> 
    <input type="button" onmouseout="btnGiocataOut(this)" onmouseover="btnGiocataOver(this)" onclick="aggiungiScommessa(6659, 12, 22, 2, 350)" value="3.50" class="ris"> 
</td> 

回答

0

我在像這樣的一次性情況下使用Firebug和jQuery。如果需要,我動態加載jQuery:$('<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js" />').appendTo(document.body);。這在Firebug控制檯中。然後我會使用類似$('input').each(function() { console.log($(this).val()); });的東西,它會打印出一個我可以輕鬆複製的列表。我會爲每一頁重複這些步驟。

1

是的,如果你想自動抓取按鈕值,而不在每一頁上使用Firebug把玩,Greasemonkey的可以做到這一點。

下面是一個應該讓你開始的腳本。請務必調整@include語句以匹配您的目標網站。

// 
// ==UserScript== 
// @name   Button value grabber 
// @namespace  Gambling 
// @description  Grabs button values. 
// @include   * 
// @require   http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js 
// ==/UserScript== 
// 

$(document).ready (Greasemonkey_main); 

function Greasemonkey_main() 
{ 
    /*--- Create a container div and area for the values. It will be styled and 
     postioned with CSS. 
    */ 
    $("body").append 
    (
      '<div id="GM_PopUpDiv">' 
     + '<h3>Button Values on this page:</h3>' 
     + '<form id="GM_ContForm"><textarea id="GM_BtnValues"><\/textarea><\/form>' 
     + '<\/div>' 
    ); 

    //--- Make it almost invisible when not moused over. 
    $('#GM_PopUpDiv').hover 
    (
     function() { $(this).stop (true, false).fadeTo (50, 1); }, 
     function() { $(this).stop (true, false).fadeTo (900, 0.15); } 
    ); 

    /*--- Copy the button values. Fine-tune the selector to taste. 
     For example, input.ris[type='button'] 
    */ 
    var NumRows = 0; 
    var BtnVals = $("input[type='button']").map (function(J) { 
        NumRows = J; 
        return this.value; 
       }).get().join ('\n') 
       ; 

    /*--- Paste the values into the textarea and adjust the height to the data 
     (within the min/max set by CSS, below). 
    */ 
    $("#GM_BtnValues").text (BtnVals). css ('height', NumRows + 4 + 'em'); 
} 


//--- This is just CSS to make the new stuff look "purty". 
GM_addStyle 
(
    '#GM_PopUpDiv             \ 
    {                \ 
     font-size:    16px;        \ 
     background:    wheat;        \ 
     border:     3px double #999999;     \ 
     margin:     5px;        \ 
                    \ 
     min-height:    100px;        \ 
     min-width:    400px;        \ 
     padding:    5px 20px;       \ 
                    \ 
     opacity:    0.15;        \ 
     z-index:    1222;        \ 
     position:    fixed;        \ 
     top:     0px;        \ 
     left:     0px;        \ 
    }                \ 
    #GM_PopUpDiv textarea           \ 
    {                \ 
     font-size:    16px;        \ 
     min-height:    6em;        \ 
     max-height:    32em;        \ 
     width:     100%;        \ 
     padding:    8px;        \ 
     word-wrap:    normal;        \ 
    }                \ 
    #GM_PopUpDiv h3             \ 
    {                \ 
     font-size:    16px;        \ 
     text-align:    left;        \ 
     margin:     0px;        \ 
    }                \ 
    ' 
); 
+0

Yesss it works!謝謝! – user444266 2010-09-15 06:59:15

+0

不客氣。 – 2010-09-15 16:18:54