-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSandboxFix.js
More file actions
39 lines (34 loc) · 1.08 KB
/
SandboxFix.js
File metadata and controls
39 lines (34 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/**
* SandboxFix
* Plugin podmieniający URL-e w sandbox Allegro linkujące do serwisu produkcyjnego.
* RTNET
*/
$.noConflict();
var __prodAllegroUrl = '//allegro.pl/';
var __sandboxAllegroUrl = '//allegro.pl.allegrosandbox.pl/';
var __observer;
jQuery(document).ready(function($) {
FixSandboxUrls($, $('body'));
if ("MutationObserver" in window) {
var observer = new MutationObserver(function(mutations) {
observer.disconnect();
FixSandboxUrls($, $('body'));
observer.observe(target, { attributes: true, childList: true, characterData: true });
});
var target = $('body').get(0);
observer.observe(target, { attributes: true, childList: true, characterData: true });
}
});
function FixSandboxUrls($, $o) {
var $links = $o.find('a[href*="' + __prodAllegroUrl + '"]');
var count = 0;
$links.each(function() {
var href = $(this).attr('href');
href = href.replace(__prodAllegroUrl, __sandboxAllegroUrl);
$(this).attr('href', href);
count ++;
});
if(console && count > 0) {
console.info('[SandboxFix] Replaced urls: ' + count);
}
}