私はGreasemonkey用のこのスクリプトを作成しています。問題は.tolowercase()です。明らかに、大文字か小文字かを問わず、URLを壊してしまいます。私はhttpとhttpsで始まるような、可能な解決策として.startswith()と.endswith()を調べました。たぶん接頭辞の検出にいくつかの '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>
編集:URLを除き、テキスト、単語、それらの自分が検出された場合は、まだ、まだテキストを.replace無視上部または下部ケースを持つことであることをその重要。小文字にない
、あなたはそれがあるとしてURLが滞在したいですか? –
あなたは正しいです – computerguy
'$( '#status')。それぞれのIDは定義によって一意でなければならないので意味がありませんまた、テキストまたは ''タグのurlですか?[mcve] – charlietfl