0
我在Chrome中使用Tampermonkey腳本,該腳本增加了Gmail中「移至」和「標籤爲」菜單的最大長度。幾個月前,當Tampermonkey自動更新到最新的主要版本時,該腳本停止工作。幾年前,我們的開發經理幫助我編寫了這個腳本,由於我是一名開發者開發人員,我沒有很好的計算它爲什麼不工作了。更新後用於Gmail的Tampermonkey腳本問題
// ==UserScript==
// @name Gmail CSS updates - menus
// @author Tyler Lesmeister
// @namespace http://www.onsharp.com
// @description Increases the height of Move to/Labels menus in Gmail
// @version 0.3
// @released 2014-03-20
// @compatible Greasemonkey
// @match https://mail.google.com/mail/u/*
// @require https://ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js
// ==/UserScript==
jq = {};
fix = {};
(function($){
jq = $;
// fix css and ui
fix.go = function(){
// update the css/styles of things we dont like
$('body').append(" <style id='monkey'> " +
" .J-M-Jz { max-height: none !important; }.J-M {max-height: 800px !important; } </style>");
};
})(jQuery.noConflict());
document.addEventListener("DOMContentLoaded", function(event) {
//console.log("DOM fully loaded and parsed");
if(window.location == window.parent.location) {
if (document.getElementById("loading")) {
fix.go();
}
}
});
;(function ($, window) {
var intervals = {};
var removeListener = function(selector) {
if (intervals[selector]) {
window.clearInterval(intervals[selector]);
intervals[selector] = null;
}
};
var found = 'waitUntilExists.found';
/**
* @function
* @property {object} jQuery plugin which runs handler function once specified
* element is inserted into the DOM
* @param {function|string} handler
* A function to execute at the time when the element is inserted or
* string "remove" to remove the listener from the given selector
* @param {bool} shouldRunHandlerOnce
* Optional: if true, handler is unbound after its first invocation
* @example jQuery(selector).waitUntilExists(function);
*/
$.fn.waitUntilExists = function(handler, shouldRunHandlerOnce, isChild) {
var selector = this.selector;
var $this = $(selector);
var $elements = $this.not(function() { return $(this).data(found); });
if (handler === 'remove') {
// Hijack and remove interval immediately if the code requests
removeListener(selector);
}
else {
// Run the handler on all found elements and mark as found
$elements.each(handler).data(found, true);
if (shouldRunHandlerOnce && $this.length) {
// Element was found, implying the handler already ran for all
// matched elements
removeListener(selector);
}
else if (!isChild) {
// If this is a recurring search or if the target has not yet been
// found, create an interval to continue searching for the target
intervals[selector] = window.setInterval(function() {
$this.waitUntilExists(handler, shouldRunHandlerOnce, true);
}, 500);
}
}
return $this;
};
}(jQuery, window));
如果我檢查Chrome中的元素以打開dev控制檯,我可以看到Tampermonkey沒有注入新的值。如果我手動更改開發控制檯中的值,我可以生成我正在查找的結果。查看截圖在下面Imgur專輯(顯然我不能發表任何圖片或者兩個以上的鏈路,因爲我至少需要10聲譽...)
因此,大家可以看到,我能夠通過控制檯修改菜單的長度就好了。 Tampermonkey沒有這樣做,我猜這是因爲我腳本中的某些內容已經過時。任何幫助將非常感激。