<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
	<id>https://luanti.nashitut.ru/index.php?action=history&amp;feed=atom&amp;title=%D0%A3%D1%87%D0%B0%D1%81%D1%82%D0%BD%D0%B8%D0%BA%3AVa%2FJWB.js%2Fworker.js</id>
	<title>Участник:Va/JWB.js/worker.js - История изменений</title>
	<link rel="self" type="application/atom+xml" href="https://luanti.nashitut.ru/index.php?action=history&amp;feed=atom&amp;title=%D0%A3%D1%87%D0%B0%D1%81%D1%82%D0%BD%D0%B8%D0%BA%3AVa%2FJWB.js%2Fworker.js"/>
	<link rel="alternate" type="text/html" href="https://luanti.nashitut.ru/index.php?title=%D0%A3%D1%87%D0%B0%D1%81%D1%82%D0%BD%D0%B8%D0%BA:Va/JWB.js/worker.js&amp;action=history"/>
	<updated>2026-11-29T08:04:03Z</updated>
	<subtitle>История изменений этой страницы в вики</subtitle>
	<generator>MediaWiki 1.46.0</generator>
	<entry>
		<id>https://luanti.nashitut.ru/index.php?title=%D0%A3%D1%87%D0%B0%D1%81%D1%82%D0%BD%D0%B8%D0%BA:Va/JWB.js/worker.js&amp;diff=27717&amp;oldid=prev</id>
		<title>Va: Новая страница: «/** https://en.wikipedia.org/w/index.php?title=User:Joeytje50/JWB.js/worker.js&amp;action=raw&amp;ctype=text/javascript  */ /**  * Web Worker for AutoWikiBrowser script. Used to run certain tasks on a parallel process to be able to terminate it.  * Idea from https://stackoverflow.com/a/66162733/1256925. Dirty hack workaround due to https://stackoverflow.com/q/66188950/1256925.  * See https://en.wikipedia.org/wiki/User:Joeytje50/JWB.js for the full script, as well as...»</title>
		<link rel="alternate" type="text/html" href="https://luanti.nashitut.ru/index.php?title=%D0%A3%D1%87%D0%B0%D1%81%D1%82%D0%BD%D0%B8%D0%BA:Va/JWB.js/worker.js&amp;diff=27717&amp;oldid=prev"/>
		<updated>2025-02-07T16:58:54Z</updated>

		<summary type="html">&lt;p&gt;Новая страница: «&lt;span class=&quot;autocomment&quot;&gt;* https://en.wikipedia.org/w/index.php?title=User:Joeytje50/JWB.js/worker.js&amp;amp;action=raw&amp;amp;ctype=text/javascript: &lt;/span&gt; /**  * Web Worker for AutoWikiBrowser script. Used to run certain tasks on a parallel process to be able to terminate it.  * Idea from https://stackoverflow.com/a/66162733/1256925. Dirty hack workaround due to https://stackoverflow.com/q/66188950/1256925.  * See https://en.wikipedia.org/wiki/User:Joeytje50/JWB.js for the full script, as well as...»&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Новая страница&lt;/b&gt;&lt;/p&gt;&lt;div&gt;/** https://en.wikipedia.org/w/index.php?title=User:Joeytje50/JWB.js/worker.js&amp;amp;action=raw&amp;amp;ctype=text/javascript&lt;br /&gt;
 */&lt;br /&gt;
/**&lt;br /&gt;
 * Web Worker for AutoWikiBrowser script. Used to run certain tasks on a parallel process to be able to terminate it.&lt;br /&gt;
 * Idea from https://stackoverflow.com/a/66162733/1256925. Dirty hack workaround due to https://stackoverflow.com/q/66188950/1256925.&lt;br /&gt;
 * See https://en.wikipedia.org/wiki/User:Joeytje50/JWB.js for the full script, as well as licensing.&lt;br /&gt;
 * Licensed under GNU GPL 2. http://www.gnu.org/copyleft/gpl.html&lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
JWB.worker.function = function() {&lt;br /&gt;
	var ret = {};&lt;br /&gt;
	&lt;br /&gt;
	function regexMatch(str, pattern, flags, callback) {&lt;br /&gt;
		var re, result;&lt;br /&gt;
		try {&lt;br /&gt;
			re = new RegExp(pattern, flags);&lt;br /&gt;
			result = str.match(re);&lt;br /&gt;
		} catch(e) {&lt;br /&gt;
			// catch and propagate invalid regexes etc.&lt;br /&gt;
			callback(undefined, e);&lt;br /&gt;
		}&lt;br /&gt;
		callback(result, undefined);&lt;br /&gt;
	}&lt;br /&gt;
	ret.match = regexMatch;&lt;br /&gt;
	&lt;br /&gt;
	function regexReplace(str, pattern, flags, rWith, callback) {&lt;br /&gt;
		var re, result;&lt;br /&gt;
		try {&lt;br /&gt;
			re = new RegExp(pattern, flags);&lt;br /&gt;
			result = str.replace(re, rWith);&lt;br /&gt;
		} catch(e) {&lt;br /&gt;
			// catch and propagate invalid regexes etc.&lt;br /&gt;
			callback(undefined, e);&lt;br /&gt;
		}&lt;br /&gt;
		callback(result, undefined);&lt;br /&gt;
	}&lt;br /&gt;
	ret.replace = regexReplace;&lt;br /&gt;
	&lt;br /&gt;
	//function to *only* replace the parsed wikitext&lt;br /&gt;
	//It excludes comments (&amp;lt;!-- --&amp;gt;), and nowiki, math, source, syntaxhighlight, pre, code, gallery and timeline tags)&lt;br /&gt;
	//Based on http://stackoverflow.com/a/23589204/1256925&lt;br /&gt;
	function unparsedReplace(str, pattern, flags, rWith, callback) {&lt;br /&gt;
		var exclude = &amp;#039;(&amp;lt;!--[\\s\\S]*?--&amp;gt;|&amp;lt;(nowiki|math|source|syntaxhighlight|pre|gallery|timeline)[^&amp;gt;]*?&amp;gt;[\\s\\S]*?&amp;lt;\\/\\2&amp;gt;)&amp;#039;;&lt;br /&gt;
		//add /i flag, to exclude the correct tags regardless of casing.&lt;br /&gt;
		//This won&amp;#039;t matter for the actual replacing, as the specified flags are used there.&lt;br /&gt;
		var replacements = 0;&lt;br /&gt;
		var global = flags.indexOf(&amp;#039;g&amp;#039;) !== -1;&lt;br /&gt;
		// build regex with exclusion list.&lt;br /&gt;
		// This re will be case insensitive, but the actual replacement done will still be case sensitive if the &amp;#039;i&amp;#039; flag is not given.&lt;br /&gt;
		// This re will also be executed globally on the string, but the separate tracker will only allow one replacement to be done if &amp;#039;g&amp;#039; is not given.&lt;br /&gt;
		try {&lt;br /&gt;
			var re = new RegExp(exclude + &amp;#039;|(&amp;#039; + pattern + &amp;#039;)&amp;#039;, flags.replace(/i|$/, &amp;#039;i&amp;#039;).replace(/g|$/, &amp;#039;g&amp;#039;));&lt;br /&gt;
			str = str.replace(re, function(match, g1, g2, g3) {&lt;br /&gt;
				if (!global &amp;amp;&amp;amp; replacements &amp;gt; 0) { // a replacement has already been made in non-global mode&lt;br /&gt;
					return match;&lt;br /&gt;
				} else if (g3 !== undefined) { //continue to perform replacement if the match is the group that&amp;#039;s supposed to be the match&lt;br /&gt;
					replacements++; // keep track of the amount of replacements made.&lt;br /&gt;
					return match.replace(new RegExp(pattern, flags), rWith);&lt;br /&gt;
				} else { //do nothing if the match is one of the excluded groups&lt;br /&gt;
					return match;&lt;br /&gt;
				}&lt;br /&gt;
			});&lt;br /&gt;
		} catch(e) {&lt;br /&gt;
			// catch and propagate invalid regexes etc.&lt;br /&gt;
			callback(undefined, e);&lt;br /&gt;
		}&lt;br /&gt;
		callback(str, undefined);&lt;br /&gt;
	}&lt;br /&gt;
	ret.unparsedreplace = unparsedReplace;&lt;br /&gt;
	&lt;br /&gt;
	onmessage = function(e) {&lt;br /&gt;
		let data = e.data;&lt;br /&gt;
		console.log(&amp;#039;worker message&amp;#039;, data);&lt;br /&gt;
		let callback = (result, err) =&amp;gt; postMessage({cmd: data.cmd, result: result, err: err});&lt;br /&gt;
		switch (data.cmd) {&lt;br /&gt;
			case &amp;#039;match&amp;#039;:&lt;br /&gt;
				regexMatch(data.str, data.pattern, data.flags, callback);&lt;br /&gt;
				break;&lt;br /&gt;
			case &amp;#039;replace&amp;#039;:&lt;br /&gt;
				regexReplace(data.str, data.pattern, data.flags, data.rWith, callback);&lt;br /&gt;
				break;&lt;br /&gt;
			case &amp;#039;unparsedreplace&amp;#039;:&lt;br /&gt;
				unparsedReplace(data.str, data.pattern, data.flags, data.rWith, callback);&lt;br /&gt;
				break;&lt;br /&gt;
			default:&lt;br /&gt;
				// postMessage({err: &amp;#039;Unknown command: &amp;#039; + data.cmd});&lt;br /&gt;
				console.log(&amp;quot;Unknown command: &amp;quot; + data.cmd);&lt;br /&gt;
				console.trace();&lt;br /&gt;
		}&lt;br /&gt;
	};&lt;br /&gt;
	&lt;br /&gt;
	return ret; // return object containing synchronous functions as a fallback.&lt;br /&gt;
};&lt;/div&gt;</summary>
		<author><name>Va</name></author>
	</entry>
</feed>