我一直在爲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