如何根据链接标题属性的不同措辞更改链接的文本?

在我的幻想足球页面中,它提供了关于对方球队的统计数据,当你鼠标hover时它会告诉你他们放弃了多少分数(见图)。

以下是与此相关的相关代码:

Was 

如何创建一个Greasemonkey脚本,将#添加到团队名称的末尾(即“Was”变为“Was – 3”

有一个问题是,有时排名表示它放弃了“第二少的分数”,在这种情况下你必须做32-2来获得绝对排名。

链接显示鼠标悬停

使用根据周围文本切换的正则表达式从title属性中提取数字。

以下是完整但未经测试的Greasemonkey脚本说明了该过程:

 // ==UserScript== // @name FF, stat delinker // @include http://YOUR_SERVER.COM/YOUR_PATH/* // @require http://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js // @require https://gist.github.com/raw/2625891/waitForKeyElements.js // @grant GM_addStyle // ==/UserScript== /*- The @grant directive is needed to work around a design change introduced in GM 1.0. It restores the sandbox. */ waitForKeyElements ("a.Inline", delinkChangeStat); function delinkChangeStat (jNode) { var rawText = jNode.attr ("title") || ""; var deltaText = ""; var mtchResult = null; //-- IMPORTANT: the single =, in the if() statements, is deliberate. //-- Like "gives up the 3rd most" if (mtchResult = rawText.match (/gives up the (\d+)[at]{2} most/i) ) { deltaText = mtchResult[1]; } //-- Like "gives up the 2nd fewest points" else if (mtchResult = rawText.match (/gives up the (\d+)[at]{2} fewest/i) ) { deltaText = 32 - parseInt (mtchResult[1], 10); } //-- ADD ADDITIONAL else if() CLAUSES HERE AS NEEDED. //-- Change the link if (deltaText) { jNode.text (jNode.text () + " - " + deltaText); } }