【问题标题】:How can I alter the colour of single letters across the whole web?如何更改整个网络中单个字母的颜色?
【发布时间】:2012-08-23 14:56:49
【问题描述】:

我正在进行一项实验,我们试图训练人们成为联觉者(他们对与数字或字母相关的颜色有额外的经验)。

我想知道是否有人对修改网络浏览器(例如 firefox)的最简单方法有什么建议,以便在他们访问的任何网页上始终以特定颜色显示 10 个字母 A-J?

非常感谢

【问题讨论】:

  • 这个问题的哪一部分是 java 特有的?
  • 我认为他们不会出现联觉症状,但会发疯(我会)。 ^^ 对于您的问题:我认为您需要现有(开源)浏览器的源代码并更改源代码以满足您的要求。然后编译它并分发给你的参与者。

标签: browser text colors


【解决方案1】:

有很多方法可以做到这一点(跨浏览器):

例如,您可以在样式表中定义 - 元素以具有不同的颜色。 加载文档时,您可以通过 JavaScript/jQuery 检查整个文档(但仅检查标签的内容,例如 )以查找您指定的字母并添加 -tag f.e.在他们周围。

不是最好的解决方案,而是一种方法。

【讨论】:

    【解决方案2】:

    看看Greasemonkey,一个专为做这种事情而设计的FireFox插件。 http://userscripts.org/ 提供了许多预制脚本,其中一些看起来可以帮助您弄清楚如何编写自己的脚本以重新着色单个字母。

    【讨论】:

      【解决方案3】:

      这里只是一个潜在解决方案的测试版的蓝图初步形式的抽象草稿:在书签中使用javascript: 前缀的链接,如下所示。

      1. 在书签工具栏中创建一个新条目
      2. 在 URL 输入中,复制/粘贴以下行:javascript:var html = document.body.innerHTML; html = html.replace(/([a-j])/ig, '<span style="color: red;">$1</span>'); while(html.match(/(<[^>]*)<[^>]+>([^<]+)<\/[^>]+>([^>]*>)/g) != null) {html = html.replace(/(<[^>]*)<[^>]+>([^<]+)<\/[^>]+>([^>]*>)/g, '$1$2$3');} document.body.innerHTML = html;
      3. 为您的书签命名(例如“A-J 到红色”)并保存
      4. 您现在可以访问任何网站并单击该书签,这会将 a 和 j 之间的所有字母变为红色

      以更简洁的方式:

      // get the content of the body
      var html = document.body.innerHTML;
      // surround any letter between a and j by a <span></span>
      html = html.replace(/([a-j])/ig, '<span style="color: red;">$1</span>');
      // but it also replaces a-j letters within html tags
      while(html.match(/(<[^>]*)<[^>]+>([^<]+)<\/[^>]+>([^>]*>)/g) != null) {
          // so if there are html tags within other html tags, delete the created <span></span>
          html = html.replace(/(<[^>]*)<[^>]+>([^<]+)<\/[^>]+>([^>]*>)/g, '$1$2$3');
      }
      // and replace the innerHTML of the body
      document.body.innerHTML = html;
      

      这确实不是最终解决方案,但是是的,也许您可​​以努力改进结果。

      PS:不要尝试使用 IE...

      【讨论】:

        猜你喜欢
        • 2014-11-26
        • 1970-01-01
        • 2017-02-01
        • 2011-08-30
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-03-31
        • 1970-01-01
        相关资源
        最近更新 更多