Skip to content

Instantly share code, notes, and snippets.

@XP1
Last active September 30, 2015 03:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save XP1/1712432 to your computer and use it in GitHub Desktop.
Save XP1/1712432 to your computer and use it in GitHub Desktop.
Fix MediaWiki: Fixes MediaWiki's WikiEditor search-and-replace extension by handling the correct line endings. Allows the search-and-replace dialog to load by disabling browser version sniffing.
// ==UserScript==
// @name Fix MediaWiki
// @version 1.02
// @description Fixes MediaWiki's WikiEditor search-and-replace extension by handling the correct line endings. Allows the search-and-replace dialog to load by disabling browser version sniffing.
// @namespace https://gist.github.com/XP1/1712432/
// @copyright 2012
// @author XP1
// @homepage https://github.com/XP1/
// @license Apache License, Version 2.0; http://www.apache.org/licenses/LICENSE-2.0
// Wikipedia:
// @include http*://wikipedia.org/*&action=*
// @include http*://*.wikipedia.org/*&action=*
// @include http*://wikimedia.org/*&action=*
// @include http*://*.wikimedia.org/*&action=*
// @include http*://wikibooks.org/*&action=*
// @include http*://*.wikibooks.org/*&action=*
// @include http*://wikinews.org/*&action=*
// @include http*://*.wikinews.org/*&action=*
// @include http*://wikiquote.org/*&action=*
// @include http*://*.wikiquote.org/*&action=*
// @include http*://wikisource.org/*&action=*
// @include http*://*.wikisource.org/*&action=*
// @include http*://wikiversity.org/*&action=*
// @include http*://*.wikiversity.org/*&action=*
// @include http*://mediawiki.org/*&action=*
// @include http*://*.mediawiki.org/*&action=*
// @include http*://wiktionary.org/*&action=*
// @include http*://*.wiktionary.org/*&action=*
// ==/UserScript==
/*
* Copyright 2012 XP1
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*jslint browser: true, vars: true, maxerr: 50, indent: 4 */
(function (window, Object) {
"use strict";
function getTrue() {
return true;
}
/**
* Overrides jQuery to retain line endings for the current user agent.
* @param $
* @see http://api.jquery.com/val/
*/
function overrideTextarea($) {
$.valHooks.textarea = {
get: function getTextareaValue(element) {
return element.value;
}
};
}
function overrideWikiEditor($) {
var wikiEditor = null;
Object.defineProperty($, "wikiEditor", {
get: function getWikiEditor() {
return wikiEditor;
},
set: function setWikiEditor(object) {
wikiEditor = object;
wikiEditor.isSupported = getTrue;
},
enumerable: true,
configurable: true
});
}
function overrideJquery() {
var $ = null;
Object.defineProperty(window, "$", {
get: function get$() {
return $;
},
set: function set$(object) {
$ = object;
overrideTextarea($);
overrideWikiEditor($);
},
enumerable: true,
configurable: true
});
}
overrideJquery();
}(this, this.Object));
@XP1
Copy link
Author

XP1 commented Jan 31, 2012

I posted this user JS in this thread:

When editing a Wikipedia page, "search and replace" functionality is malfunctioning with Opera.:
http://my.opera.com/community/forums/topic.dml?id=1051742

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment