更新后 Gmail 的 Tampermonkey 脚本问题
Issues with Tampermonkey script for Gmail after update
我在 Chrome 中使用了一个 Tampermonkey 脚本,它增加了 Gmail 中 "Move to" 和 "Label as" 菜单的最大长度。当 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 中的元素以打开开发控制台,我可以看到 Tampermonkey 没有注入新值。如果我手动更改开发控制台中的值,我就能生成我正在寻找的结果。请参阅下面的 Imgur 相册中的屏幕截图(显然我不能 post 任何图像或包含两个以上的链接,因为我至少需要 10 个声望...)
如您所见,我可以通过控制台修改菜单的长度。 Tampermonkey 没有这样做,我猜这是因为我的脚本中的某些内容已经过时了。任何帮助将不胜感激。
我决定从头开始。我能够使用以下脚本完成同样的事情:
// ==UserScript==
// @name Gmail Enhancements
// @namespace http://tyler.bio
// @version 0.1
// @description Make Gmail better
// @author Tyler Lesmeister
// @match https://mail.google.com/mail/*
// @require http://code.jquery.com/jquery-latest.js
// @grant GM_addStyle
// ==/UserScript==
// increase height of folder/label menus
GM_addStyle(" .J-M {max-height: 800px !important; } .J-M-Jz { max-height: 800px !important; } ");
我在 Chrome 中使用了一个 Tampermonkey 脚本,它增加了 Gmail 中 "Move to" 和 "Label as" 菜单的最大长度。当 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 中的元素以打开开发控制台,我可以看到 Tampermonkey 没有注入新值。如果我手动更改开发控制台中的值,我就能生成我正在寻找的结果。请参阅下面的 Imgur 相册中的屏幕截图(显然我不能 post 任何图像或包含两个以上的链接,因为我至少需要 10 个声望...)
如您所见,我可以通过控制台修改菜单的长度。 Tampermonkey 没有这样做,我猜这是因为我的脚本中的某些内容已经过时了。任何帮助将不胜感激。
我决定从头开始。我能够使用以下脚本完成同样的事情:
// ==UserScript==
// @name Gmail Enhancements
// @namespace http://tyler.bio
// @version 0.1
// @description Make Gmail better
// @author Tyler Lesmeister
// @match https://mail.google.com/mail/*
// @require http://code.jquery.com/jquery-latest.js
// @grant GM_addStyle
// ==/UserScript==
// increase height of folder/label menus
GM_addStyle(" .J-M {max-height: 800px !important; } .J-M-Jz { max-height: 800px !important; } ");