Wikipedia talk:WikiProject JavaScript: Difference between revisions
Content deleted Content added
reply |
→Nested RegExp: refine reply |
||
Line 104:
Sorry, but I don't understand what you are trying to achieve. If you want to remove red links from the DOM (in the generated code of the view), then you can use Javascript (faster) or jQuery (slower) to remove or replace all of them eventually at once, or do more things on each of them in a loop. With Javascript you need to use one of "getElementsByClassName" (for example applied to <code>class="new"</code>) or "getElementsByTagName" for all <code><a></code> elements, and then you can apply styles ('_color_', '_cursor_', …) or replace them with your own content such as their "innerHTML" values. With jQuery >= 1.2 you can use something like <code>$(".new").replaceWith(function() { return $(this).text(); });</code> or <code>$(".new").replaceWith(function() { return this.innerHTML; });</code>, while with jQuery >= 1.4 you can use the <code>unwrap</code> function like this: <code>$(".new").contents().unwrap();</code>. jQuery seems to be shorter, but this is because you do not see the whole code that is behind the execution of it, and it is much slower than doing it in native Javascript (when it is well written, of course). All of them, Javascript and jQuery, should be wrapped into a document ready function (via Javascript or jQuery), a setTimeout functions or both. If you need to store their values, then you can create a <code>for</code> or a <code>while</code> loop for each of them and the do whatever you want to. Of course, if you are working on the source code, then the above does not apply at all. About the regex, I need more about the data, plus tests and examples. The reason for its multiple matches has been well explained above. Just a note, if you are sending and parsin a huge quantity of data, for example the whole content of an article, then something like [[Perl|PERL]] is always the faster and the better solution possible because it was conceived for reporting of the big log files such as those generated by a server. [[AWK]] and [[Sed|sed]] are also good with this. Unfortunately, I do not think that they are available here. –[[User:Pjoef|p<span style="color: #802400">joe</span>f]] <small>(''[[User talk:Pjoef|talk]]'' • [[Special:Contributions/Pjoef|contribs]])</small> 12:18, 6 May 2017 (UTC)
: {{ping|Pjoef|Jdh8}} The script is [[User:The Transhumanist/OLUtils.js]], and the section we are working on here is for processing outlines, and starts with this:
: {{ping|Pjoef|Jdh8}} First, the script is supposed to remove list item entries (including bullet and carriage return) that are comprised entirely of redlinks, but only if they have no children. Red end nodes. It goes through several iterations, just in case the removal of a red end node renders other red entries into end nodes. After all those have been removed, then the script delinks the remaining embedded red links, and finally deletes any red category links. [[User talk:The Transhumanist|<i>The Transhumanist</i>]] 14:12, 6 May 2017 (UTC)▼
:<code>if (document.title.indexOf("Outline ") != -1) {</code>.
▲:
=== The whole regex ===
|