Wikipedia:User scripts/Requests/Archive 4: Difference between revisions

Content deleted Content added
m Archiving 1 discussion(s) from Wikipedia:User scripts/Requests) (bot
Line 194:
Having a floating sidebar on the right of the screen would allow for quicker use of Wikipedia, and I would like this to be implemented as a script (if possible). Cheers! [[User:23lobor|creativeRaja'']]<sup>[[User talk:23lobor|t@lk]]</sup> 16:20, 14 October 2019 (UTC)
:Check out the Timeless skin (in your preferences) if you're not afraid of everything else looking different as well. Can't find anything in [[WP:US/L]] about a right-hand sidebar, but I feel like I remember one existing. [[User:Enterprisey|Enterprisey]]&nbsp;([[User talk:Enterprisey|talk!]]) 04:44, 16 October 2019 (UTC)
 
{{Clear}}
== unreliable.js, a predatory journals/vanity press highlighter ==
{{resolved}}
Similar to [[User:Anomie/linkclassifier.js]]/[[User:Anomie/linkclassifier.css]], I'd like a user script to highlight citations to predatory journals and vanity presses. The regex can be stolen/adapted from [[Special:AbuseFilter/891]].
 
Basically, if a URL with a ___domain that matches the <code>urls := </code> part, highlight those links by making them... let's say [https://asdfadf.com pink]→{{Highlight round|[https://asdfadf.com pink]|bc=#ffdddd;}}/some annoying color. Likewise, if a DOI matches the <code>dois :</code> part, highlight those in annoying pink as well ({{doi|10.4172/omicsjournalofnonsense}}→[[Digital object identifier|doi]]:{{highlight round|10.4172/omicsjournalofnonsense|bc=#ffdddd;}}). Or whatever other colour. If the script cannot dynamically be kept in sync with [[Special:AbuseFilter/891]], I can take over and put it at [[User:Headbomb/unreliable.js]] and maintain it after that.
 
The idea is that, if you encounter a citation like
*Xu, Ting (2017-01-06). "[http://www.scholink.org/ojs/index.php/rem/article/view/777 The Relationship between Interest Rates, Income, GDP Growth and House Prices]". Research in Economics and Management. 2 (1): 30. doi:10.22158/rem.v2n1p30. ISSN 2470-4393.
You get presented with something like
*Xu, Ting (2017-01-06). "{{Highlight round|[http://www.scholink.org/ojs/index.php/rem/article/view/777 The Relationship between Interest Rates, Income, GDP Growth and House Prices]|bc=#ffdddd;}}". Research in Economics and Management. 2 (1): 30. doi:{{Highlight round|10.22158/rem.v2n1p30|bc=#ffdddd;}}. ISSN 2470-4393.
 
And know something's off. Multiple 'classes' and colors should be supported (each customisable as enabled/disabled), so that additional things like {{highlight round|blacklisted links|bc=#dddddd;}} and ''possibly'' unreliable sources (like {{highlight round|Forbes.com|bc=#ffffdd;}}, which will [[Wikipedia:Reliable_sources/Perennial_sources#Forbes|often be fine]], but [[Wikipedia:Reliable_sources/Perennial_sources#Forbes.com_contributors|sometimes not]]) can also be highlighted. &#32;<span style="font-variant:small-caps; whitespace:nowrap;">[[User:Headbomb|Headbomb]] {[[User talk:Headbomb|t]] · [[Special:Contributions/Headbomb|c]] · [[WP:PHYS|p]] · [[WP:WBOOKS|b]]}</span> 07:16, 6 February 2020 (UTC)
 
:The basic version would look like this:
:<source lang=js>
var PREDATORY_HREFS_RGX = /academicjournals\.com|academicjournals\.net|academicjournals\.org|academicpub\.org|academicresearchjournals\.org|aiac\.org\.au|aicit\.org|alliedacademies\.org|ashdin\.com|aspbs\.com|avensonline\.org|biomedres\.info|biopublisher\.ca|bowenpublishing\.com|ccsenet\.org|cennser\.org|clinmedjournals\.org|cluteinstitute\.com|cpinet\.info|cscanada\.net|davidpublisher\.org|etpub\.com|eujournal\.org|growingscience\.com|hanspub\.org|hoajonline\.com|hrmars\.com|iacsit\.org|iamure\.com|\.idosi\.org|igi-global\.com|iises\.net|imedpub\.com|informaticsjournals\.com|innspub\.net|intechopen\.com|intechweb\.org|interesjournals\.org|ispacs\.com|ispub\.com|julypress\.com|juniperpublishers\.com|kowsarpub\.com|kspjournals\.org|m-hikari\.com|macrothink\.org|mathewsopenaccess\.com|mecs-press\.org|oapublishinglondon\.com|oatext\.com|omicsonline\.org|ospcindia\.org|researchleap\.com|sapub\.org|scholink\.org|scialert\.net|scidoc\.org|sciencedomain\.org|sciencedomains\.org|sciedu\.ca|sciencepg\.com|sciencepub\.net|sciencepubco\.com|sciencepublication\.org|sciencepublishinggroup\.com|scipg\.net|scipress\.com|scirp\.org|scopemed\.com|sersc\.org|sphinxsai\.com|\.ssjournals\.com|thesai\.org|waset\.org|witpress\.com|worldwidejournals\.com|zantworldpress\.com/i;
 
var PREDATORY_DOIS_RGX = /doi.org\/10\.(11648|1166|1234|12677|12692|12720|12988|13005|13172|13188|14257|14303|14419|1453|14569|14662|15415|15373|15761|17265|18005|18052|18311|18775|19030|19044|19070|19080|1999|20472|20849|20902|21102|21767|22158|23937|2495|30654|30845|35841|36648|3844|3923|3968|4018|4156|4172|4236|4303|5267|5296|5376|5430|5455|5539|5567|5580|5772|5812|5815|5829|5897|5899|5923|5963|6007|7243|7439|7537|7575|7718|7763|9734)/i;
 
var cssRules = {
"margin-right": "0.1em",
"padding": "3px 4px 2px",
"background-color": "#ffdddd",
"border": "1px",
"border-radius": "3px",
"box-shadow": "0.1em 0.1em 0.25em rgba(0,0,0,0.75)",
"-moz-box-shadow": "2px 2px 4px #A0A080",
"-webkit-box-shadow": "2px 2px 4px #A0A080",
"box-shadow": "2px 2px 4px #A0A080"
};
 
$('.mw-parser-output a.external').each(function() {
if (PREDATORY_HREFS_RGX.test(this.href)) {
$(this).css(cssRules);
} else if (PREDATORY_DOIS_RGX.test(this.href)) {
$(this).css(cssRules);
}
});
</source>
:Hopefully someone else can do the rest and provide customisability you ask for.
:You should definitely simplify the massive regex (for instance, make the .com part common for all .com domains) for better performance. [[User:SD0001|SD0001]] ([[User talk:SD0001|talk]]) 12:43, 6 February 2020 (UTC)
::I can regex, what I can't do is .js from scratch, but the above should give me enough to get started. I'll give that piece of code a shot this afternoon. Performance probably isn't much of an issue. &#32;<span style="font-variant:small-caps; whitespace:nowrap;">[[User:Headbomb|Headbomb]] {[[User talk:Headbomb|t]] · [[Special:Contributions/Headbomb|c]] · [[WP:PHYS|p]] · [[WP:WBOOKS|b]]}</span> 13:54, 6 February 2020 (UTC)
:::{{Re|SD0001}} [[User:Headbomb/unreliable.js]] doesn't seem to work, including your [https://en.wikipedia.org/w/index.php?title=User:Headbomb/unreliable.js&oldid=939445049 original code]. This can be tested on [[Science Publishing Group]], which has both a url and doi that should match. &#32;<span style="font-variant:small-caps; whitespace:nowrap;">[[User:Headbomb|Headbomb]] {[[User talk:Headbomb|t]] · [[Special:Contributions/Headbomb|c]] · [[WP:PHYS|p]] · [[WP:WBOOKS|b]]}</span> 14:45, 6 February 2020 (UTC)
:::::Nevermind, I had a brainfart. Namely, I forgot to do [https://en.wikipedia.org/w/index.php?title=User:Headbomb/monobook.js&diff=939456681&oldid=939455109 this]. &#32;<span style="font-variant:small-caps; whitespace:nowrap;">[[User:Headbomb|Headbomb]] {[[User talk:Headbomb|t]] · [[Special:Contributions/Headbomb|c]] · [[WP:PHYS|p]] · [[WP:WBOOKS|b]]}</span> 16:04, 6 February 2020 (UTC)
::::::I should have mentioned that for it to load reliably, it needs to be ensured that the page has fully loaded before the script code is run. You can do this by wrapping the whole code between <code>(function() {</code> ... script code comes here ... <code>})();</code>
::::::I see that you removed doi.org from the DOIs regex - this would mean that anyinnocentdomain.com/3424310.11648 would be flagged, as the link's url contains "10.11648". Markup like <code>(doi)*?[ ]*?[=\|\:][ ]*?</code> won't work here as we're checking against the HTML of the page (specifically, against external link URLs), not against the wikitext. [https://en.wikipedia.org/w/index.php?title=User:Headbomb/unreliable.js&diff=939445982&oldid=939445626] the i makes the regex test case-insensitive. [[User:SD0001|SD0001]] ([[User talk:SD0001|talk]]) 17:16, 6 February 2020 (UTC)
:::::::Good to know. Didn't know about /i, but that will be useful. As for removing doi.org, that's desired to pickup "Journal of crap 10.4172/asdf10354" that might not make use of templates. false positives are far and few between, although normally I might add a final <code>...\/</code> at the end to ensure it matches a <code>10.4172/</code> and not just <code>10.4172</code>. Clearly "<code>(PRED_DOIS_RGX.test(this.href))</code>" needs tweaking to look outside hrefs, but to what, I don't yet know. &#32;<span style="font-variant:small-caps; whitespace:nowrap;">[[User:Headbomb|Headbomb]] {[[User talk:Headbomb|t]] · [[Special:Contributions/Headbomb|c]] · [[WP:PHYS|p]] · [[WP:WBOOKS|b]]}</span> 17:21, 6 February 2020 (UTC)
::::::::{{re|Headbomb}} You can check whole reference texts (anything within &lt;ref> tags) by using code like:
::::::::<source lang=js>
$('span.reference-text').each(function() {
if (DOI_RGX.test(this.textContent)) {
$(this).css(CSSRULE);
}
}); </source> [[User:SD0001|SD0001]] ([[User talk:SD0001|talk]]) 17:47, 6 February 2020 (UTC)
{{unindent}} {{Re|SD0001}} Well, I don't want this to be restricted to ref tags either. I want to find those wherever on the page they may be. &#32;<span style="font-variant:small-caps; whitespace:nowrap;">[[User:Headbomb|Headbomb]] {[[User talk:Headbomb|t]] · [[Special:Contributions/Headbomb|c]] · [[WP:PHYS|p]] · [[WP:WBOOKS|b]]}</span> 17:56, 6 February 2020 (UTC)
::{{done}} Also, if something could only be detected/highlighted in specific namespaces, that would be good. For instance the current <code>var WIKI_HREFS_RGX</code> should really only be highlighted in main/draft spaces. &#32;<span style="font-variant:small-caps; whitespace:nowrap;">[[User:Headbomb|Headbomb]] {[[User talk:Headbomb|t]] · [[Special:Contributions/Headbomb|c]] · [[WP:PHYS|p]] · [[WP:WBOOKS|b]]}</span> 23:27, 6 February 2020 (UTC)
{{Ping|SD0001}}, any idea for how to look outside of references/links? &#32;<span style="font-variant:small-caps; whitespace:nowrap;">[[User:Headbomb|Headbomb]] {[[User talk:Headbomb|t]] · [[Special:Contributions/Headbomb|c]] · [[WP:PHYS|p]] · [[WP:WBOOKS|b]]}</span> 01:33, 11 February 2020 (UTC)
:{{re|Headbomb}} Thanks for all your work on this so far! When finished, I do think this will be a ''very'' useful script, particularly for NPP/AFC folks.
:Regarding looking outside references, it's a bit complicated. We'll need to iterate over all the text nodes on the page, extract the index at which the search hit begins, and wrap that in a span element, upon which we can then apply custom stylings. I can code this for you when I have time. But where the does the desire for doing this outside ref tags come from? [[User:SD0001|SD0001]] ([[User talk:SD0001|talk]]) 18:02, 12 February 2020 (UTC)
{{Re|SD0001}} A typical example would be in further reading section or external link sections where you could have something like
<pre>
==Further reading
* Smith, J. (2019) "Article of things" ''Journal of Nonsense'' doi: 10.4172/123456798
</pre>
It doesn't need to highlight the whole doi (although that would be neat if it could), but just the prefix/whatever it matches would be enough.
&#32;<span style="font-variant:small-caps; whitespace:nowrap;">[[User:Headbomb|Headbomb]] {[[User talk:Headbomb|t]] · [[Special:Contributions/Headbomb|c]] · [[WP:PHYS|p]] · [[WP:WBOOKS|b]]}</span> 18:08, 12 February 2020 (UTC)
 
*https://markjs.io/ may be useful for something here. &#32;<span style="font-variant:small-caps; whitespace:nowrap;">[[User:Headbomb|Headbomb]] {[[User talk:Headbomb|t]] · [[Special:Contributions/Headbomb|c]] · [[WP:PHYS|p]] · [[WP:WBOOKS|b]]}</span> 19:00, 12 February 2020 (UTC)