Greasemonkey替换代码

时间:2015-11-18 14:01:59

标签: javascript html replace greasemonkey userscripts

我希望将public class ModelData { public string name; public DateTime DT; public int real; public int trade; public int position; public int dayPnl; } List<ModelData> modelData; var dates = modelData.Select(x => x.DT.Date).Distinct(); var names = modelData.Select(x => x.name).Distinct(); foreach (var aDate in dates) { var dateRealTrades = modelData.Select(x => x) .Where(x => x.DT.Date.Equals(aDate) && x.real.Equals(1)); foreach (var aName in names) { var namesRealTrades = dateRealTrades.Select(x => x) .Where(x => x.name.Equals(aName)); // DO MY PROCESSING } } 替换为openProfileOrUnlockUser这样的元素:

openProfile

我现在拥有的是:

<a ng-href="/profile/CRYJIEjJGv+th/a/aQmDoFisAhE+LSldMLJbk1VCTJUJMeCqzFw0xZb9Q=="
   ng-click="user.openProfileOrUnlockUser(item._type)" 
   class="show overflow-hidden absolute-fill" 
   eat-click="" 
   href="/profile/CRYJIEjJGv+th/a/aQmDoFisAhE+LSldMLJbk1VCTJUJMeCqzFw0xZb9Q==">

但它不起作用。

P.S。搜索了2个小时但没有工作。

1 个答案:

答案 0 :(得分:2)

ng-click是一个属性,而不是文本节点,因此您的xpath不起作用。

明显的选择是document.querySelectorAll

[].forEach.call(document.querySelectorAll('[ng-click*="openProfileOrUnlockUser"]'), 
    function(node) {
        node.setAttribute('ng-click', 
            node.getAttribute('ng-click').replace('openProfileOrUnlockUser', 'openProfile')
        );
    }
);