Tampermonkey 用户脚本如何禁用站点 CSS 的单个设置?

How can a Tampermonkey userscript disable a single setting of a site's CSS?

我已经修改了一个在网上找到的脚本以获得我喜欢的格式,但是 Gmail 中的 CSS 弄乱了它的显示方式。

使用 Chrome 我发现我可以切换 max-width 并且它可以正确显示,但我不够聪明,不知道如何将其输入到此脚本中。

如何让脚本为 .xW class 禁用 max-width

Original Script Source

我修改的脚本:

// ==UserScript==
// @name        Gmail - show FORMATTED full date and time in mail list
// @description Just show the full date and time on the list instead of only short date. Useful if you need to create a report and you base on your activity and it's timing. Or when you look at mails and want to find one visually by looking on times.
// @include     https://mail.google.com/mail/*
// @version 0.0.1.20180924133221
// @namespace https://greasyfork.org/users/153157
// ==/UserScript==

var formatDate = function(dateString) {
  var dateTime = new Date(dateString);
  return dateTime.toLocaleString();
};

(function() {
  window.setInterval(function() {
    var date_titles_main = Array.from(document.getElementsByClassName("xW xY"));
    var date_titles_thread = Array.from(document.getElementsByClassName("g3"));
    date_titles_main.forEach(function(element, index, array) {
      var elements = element.childNodes;
      var title = elements.length > 0 ? elements[0].title : false;
      if (title) {
        title = formatDate(title);
      }
      if (title && elements[0].innerHTML != title) { elements[0].innerHTML = title; }
    });
    date_titles_thread.forEach(function(element, index, array) {
      if (element.title && element.innerHTML != element.title) { element.innerHTML = formatDate(element.title); }
    });
    Array.from(document.getElementsByClassName("xX")).forEach(function(element, index, array) {
      element.style.width = '80ex';
    });
  }, 2000);
})();

你会使用 the CSS unset value.

另请注意:

  • Use the CSS cascade for most stuff like this.
  • 您不需要 (function() { 位。 (GM/TM 脚本默认已包装。)

这是修改后的脚本(未经测试,因为我很少使用 Gmail):

// ==UserScript==
// @name        Gmail - show FORMATTED full date and time in mail list
// @description Just show the full date and time on the list instead of only short date. Useful if you need to create a report and you base on your activity and it's timing. Or when you look at mails and want to find one visually by looking on times.
// @include     https://mail.google.com/mail/*
// @version     0.1.0.20181023
// @namespace   https://greasyfork.org/users/153157
// @grant       GM_addStyle
// ==/UserScript==

var formatDate = function (dateString) {
    var dateTime = new Date (dateString);
    return dateTime.toLocaleString ();
};

window.setInterval (function () {
    var date_titles_main = Array.from (document.getElementsByClassName ("xW xY"));
    var date_titles_thread = Array.from (document.getElementsByClassName ("g3"));
    date_titles_main.forEach (function (element, index, array) {
        var elements = element.childNodes;
        var title = elements.length > 0 ? elements[0].title : false;
        if (title) {
            title = formatDate (title);
        }
        if (title && elements[0].innerHTML != title) { elements[0].innerHTML = title; }
    } );
    date_titles_thread.forEach (function (element, index, array) {
        if (element.title && element.innerHTML != element.title) { element.innerHTML = formatDate (element.title); }
    } );
}, 2000);

GM_addStyle ( `
    .xX { width: 80ex !important; }
    .xW { max-width: unset !important; }
` );