我一直在为Greasemonkey编写这个脚本。问题是.tolowercase()显然它使任何大写的小写,这会破坏URL的。我研究过.startswith()和.endswith()作为可能的解决方案,例如以http和https开头;也许前缀检测一些'http *'?不管怎么说,这是下面的代码,在此先感谢:.tolowercase()仅包含除URL之外的文本?
// ==UserScript==
// @name twitter intent
// @namespace random
// @description twitter intent popupwindow text replace
// @include https://twitter.com/intent/*
// @version 1
// @grant none
// @require http://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js
// ==/UserScript==
$('#status').each(function() {
var text = $(this).text();
$(this).text(text.toLowerCase()
.replace('... ', ' ... ')
.replace('health ', '#health ')
.replace('video', 'Video')
.replace('emergency', '#emergency')
.replace('climate change', '#climatechange')
.replace('climate ', '#climate ')
);
});
这是代码之前,HTML是跑就可以了。
<textarea id="status" name="status" required="" autofocus="" aria-required="true" aria-describedby="post-error char-count">EPA shuts down program helping states adjust to climate change http://hill.cm/FH2iWpq</textarea>
编辑:它的重要,除了网址,文字是有忽略,如果检测到的话他们的自我,但仍.replace文字大写或小写。
所以,你要的网址留下来,因为它是什么? –
你是对的 – computerguy
'$('#status')。each('没有意义,因为ID的定义必须是唯一的,也可以是URL中的文字或''标签?提供[mcve] – charlietfl