2012-06-14 36 views
1

我試圖獲得一個相當簡單的腳本,它保留一個值並在GreaseMonkey:Scriptish的後繼中檢索它。GM_setValue未定義

瀏覽器:Firefox 9.0
Scriptish:0.1.7
在Windows 7旗艦版64位

// ==UserScript== 
// @id    testSerialization 
// @name   Test Serialization 
// @version  1.0 
// @namespace  com.mobilvox.com 
// @author   
// @description  
// @include  http://www.google.com/ 
// @run-at   document-end 
// ==/UserScript== 

GM_setValue("isCurrent", true); 
GM_log("Is this script current? " + GM_getValue("isCurrent", false)); 

當我運行它,我得到:

[10:29:59.074] GM_setValue is not defined 
@Scratchpad:29 
@ Scratchpad:29 
+0

嘗試刪除元數據中的空白條目(在這種情況下爲'@ author'和'@ description')。損壞的或不正確的元數據塊有時會給出這種類型的錯誤(或用於)。確保元數據塊已滿,在文件中刷新 - 在前導'//'之前沒有空格或縮進。 –

回答

1

這看起來像一個可能的錯誤,請參閱相關的錯誤,如"GM_setValue not working"

可能採取的行動:

  1. 火狐9越來越過時。升級到FF 12或FF 13並查看問題是否仍然存在。
  2. 文件a bug report for Scriptish
+0

我在FF的「發佈頻道」,我很驚訝它沒有要求我升級。哦,好吧...... *手動執行*我發現他們剛剛完成一個發佈後,我切換到了GreaseMonkey ......但是我仍然遇到了GM的問題......無法重新保存一個變量......但這是另一個問題... – leeand00

2

我有一個完整的工作代碼與jQuery和GM_代碼。試試這個:

// ==UserScript== 
// @name   GM_ debug script 
// @description checking GM_setValue and GM_getValue with jQuery 
// @namespace  eaposztrof 
// @include  * 
// @require  http://code.jquery.com/jquery-1.9.1.js 
// @grant  GM_getValue // [grants][1] 
// @grant  GM_setValue 
// ==/UserScript== 

function GM_getValueUTF8(key) { // UTF8 safe 
    var value = GM_getValue(key); 
    return (value && value.length) ? decodeURI(value) : ''; 
} 

function GM_setValueUTF8(key, value) { 
    GM_setValue(key, encodeURI(value)); 
} 

    GM_setValueUTF8('asd','GM_setValue, GM_getValue working! press [Alt+X] to check with jQuery'); 
    alert(GM_getValueUTF8('asd')); 

(function(){ 
    this.$ = this.jQuery = jQuery.noConflict(true); 

    $(document).ready(function() { 

     $ (document).keydown (function (e) { 
      switch (e.keyCode) { 
       case 88: // "x" 
        if (e.altKey) { 
         setTimeout(function() { // [workaround][2] 
          GM_setValueUTF8('asd','GM_setValue, GM_getValue working inside jQuery'); 
          alert(GM_getValueUTF8('asd')); 
         }, 0); 
        } 
      } 
     }); 
    }); 
} 
// 
)(); 
+0

鏈接已死亡... – trex005