// ==UserScript== // @name MyDealz Enhancer // @namespace mydealz_enhancer // @description Verbessert Funktionen von MyDealz, oder stellt sie wieder her // @author BAERnado // @include http://www.mydealz.de/* // @version 1.002 // @require http://code.jquery.com/jquery-2.1.4.min.js // @grant GM_getValue // @grant GM_setValue // @grant GM_log // @downloadURL none // ==/UserScript== function ModifyPage() { var defaultSettings = {behavior: {showGreenDots: true}, comments: {maxQuoteLevel: 1, editReason: '', signature: '', useSignature: false}, deals: {hide: ''}, userMenuDirect : {pn: false, account: false}, hideAds: {topBar: true, gsWidget: true, inside: true,nlSection: true, app: true}, moveButtons: {_: true, deals: true, gutscheine: true, freebies: true, custom: true, gesuche: false, diverses: false, kleinanzeigen: false}, fromTo: {deals: 'deals-new', gutscheine: 'gutscheine-new', freebies: 'freebies-new', gesuche: 'gesuche', diverses: 'diverses', kleinanzeigen: 'kleinanzeigen', bugreports: 'bugreports'}}; var settings = {}; var timer = {}; var save = {pn: {}}; var userName; $.fn.hasAttr = function(name) { return this.attr(name) !== undefined; }; $.fn.extend({ insertAtCaret: function(myValue) { var elem = this[0]; if (document.selection) { elem.focus(); sel = document.selection.createRange(); sel.text = myValue; elem.focus(); } else if (elem.selectionStart || elem.selectionStart == '0') { var startPos = elem.selectionStart; var endPos = elem.selectionEnd; var scrollTop = elem.scrollTop; var oldLength = elem.value.length; elem.value = elem.value.substring(0, startPos)+myValue+elem.value.substring(endPos,elem.value.length); elem.focus(); elem.selectionStart = startPos + elem.value.length - oldLength; elem.selectionEnd = startPos + elem.value.length - oldLength; elem.scrollTop = scrollTop; } else { elem.value += myValue; elem.focus(); } } }); $.fn.setCursorPosition = function(pos) { var _elem = this[0]; if (_elem.setSelectionRange) { _elem.setSelectionRange(pos, pos); } else if (_elem.createTextRange) { var range = _elem.createTextRange(); range.collapse(true); if(pos < 0) { pos = $(_elem).val().length + pos; } range.moveEnd('character', pos); range.moveStart('character', pos); range.select(); } } function printUTCDate(_date) { return ('0'+_date.getUTCHours().toString()).replace(/^0*([0-9]{2})$/, '$1') + ':' + ('0'+_date.getUTCMinutes().toString()).replace(/^0*([0-9]{2})$/, '$1') + ':' + ('0'+_date.getUTCSeconds().toString()).replace(/^0*([0-9]{2})$/, '$1'); } function printDate(_date) { return ('0'+_date.getHours().toString()).replace(/^0*([0-9]{2})$/, '$1') + ':' + ('0'+_date.getMinutes().toString()).replace(/^0*([0-9]{2})$/, '$1') + ':' + ('0'+_date.getSeconds().toString()).replace(/^0*([0-9]{2})$/, '$1'); } function timeTick() { var _allTimes = document.getElementsByClassName('bf-carousel-date'); var _remain; var _until; var _diffDate; var _toDate; var _diffTime; var _now = new Date(); for(var _i = 0; _i < _allTimes.length; _i++) { _until = _allTimes[_i]; _remain = _allTimes[_i].parentNode.getElementsByClassName('bf-carousel-date-remain')[0]; _toDate = new Date(); _toDate.setTime(parseInt(_until.innerHTML, 10)*1000); _diffDate = new Date(); _diffTime = _toDate.getTime() - _now.getTime(); if(_diffTime <= 0) { $(_allTimes[_i]).parent().find('.space--left-2').text(/Beginnt in/.test($(_allTimes[_i]).parent().find('.space--left-2').text('')) ? 'Begonnen' : 'Abgelaufen'); $(_remain).remove(); } else { _diffDate.setTime(_diffTime); _remain.innerHTML = printUTCDate(_diffDate); // + ' (' + printDate(_toDate) + ')'; } } } function addTimes() { var _allTimes = document.getElementsByClassName('bf-carousel-date'); var _newSpan; for(var _i = 0; _i < _allTimes.length; _i++) { _allTimes[_i].style.display = 'none'; _newSpan = document.createElement('span'); _newSpan.setAttribute('class', 'bf-carousel-date-remain'); _allTimes[_i].parentNode.insertBefore(_newSpan, null); } timeTick(); window.setInterval(timeTick, 1000); } function fixPositions() { var _allElems = document.getElementsByTagName('article'); for(var _i = 0;_i < _allElems.length; _i++) { _allElems[_i].setAttribute('style', 'position: absolute; width: 1200px; left: 0px; top: ' + _i*404 + 'px'); } window.setTimeout("document.getElementsByTagName('article')[0].parentNode.setAttribute('style', 'height: " + _allElems.length * 404 + "px;');", 20); } function changeLinks() { var _allLinks = $('a.navTrigger1, .navTrigger1-row-items .menu:last .menu-list .navMenu1-item'); var _fromTo = settings.fromTo; var _loc; $(_allLinks).each(function (_lInd, _lVal) { var _link = $(_lVal); if(_link.hasAttr('href')) { _loc = _link.attr('href').replace(/^https?:\/\/www\.mydealz\.de(\/(hot|discussed|new)?)?$/, '/').replace(/^https?:\/\/www\.mydealz\.de\/([a-zA-Z-]+)?$/, '$1').replace(/-?(new|discussed)?$/,''); if(_loc in _fromTo) { _link.attr('href', _link.attr('href').replace(/^(https?:\/\/www\.mydealz\.de).*$/, '$1' + '/' + _fromTo[_loc])); } } }); } function remodelNavBar() { // Besten Dank an lolnickname für die Vorlage var _subMenu = $('header strong[data-handler="menu"]'); _subMenu.find('span[class!="navTrigger-arrow"]').remove(); _subMenu = _subMenu.parent().parent(); var _buttonIndex = 1; var _buttonBeforeSubIndex = 0; var _button; var _subHiddenButton; var _selected; var _moreHighlight = true; for(_bInd in settings.moveButtons) { if(_bInd == '_') { _button = $('.navTrigger1-row-items > li > a.navTrigger1[href="http://www.mydealz.de/"], .navTrigger1-row-items li.menu ul.menu-list li.hide--downThrough- a[href="http://www.mydealz.de/"]'); } else { _button = $('.navTrigger1-row-items > li > a.navTrigger1[href*="' + _bInd + '"], .navTrigger1-row-items li.menu ul.menu-list li.hide--downThrough- a[href*="' + _bInd + '"]'); } _selected = _button.hasClass('navTrigger1--selected') || _button.hasClass('navMenu1-item--selected'); if(_button.hasClass('navTrigger1') && settings.moveButtons[_bInd]) { _button.attr('class', 'navTrigger1 navTrigger1hide--upTo-menu' + _buttonIndex++); } else if (_button.hasClass('navTrigger1') && !settings.moveButtons[_bInd]) { // Verschiebe in Untermenu _subMenu.find('li.hide--downThrough- a.navMenu1-item').eq(_buttonBeforeSubIndex++).parent().before(_button.attr('class', 'navMenu1-item').parent().attr('class', 'hide--downThrough-')); } else if(_button.hasClass('navMenu1-item') && settings.moveButtons[_bInd]) { // Verschiebe ins Hauptmenu _subMenu.before(_button.removeClass('navMenu1-item navMenu1-item--selected').addClass('navTrigger1').parent().removeClass('navMenu1-item hide--downThrough-').addClass('tGrid-cell hide--upTo-menu' + _buttonIndex)); } if(_selected) { if(_button.hasClass('navTrigger1')) { _button.addClass('navTrigger1--selected'); _moreHighlight = false; } else { _button.addClass('navMenu1-item--selected'); if($('header.header .navTrigger1-row .navTrigger1-row-items a.navTrigger1[href="' + _button.attr('href') + '"]').length == 0) { _moreHighlight = true; } else { _moreHighlight = false; } } } } for(_buttonIndex = 1; _buttonIndex <= 4; _buttonIndex++) { _button = $('.navTrigger1-row-items > li.hide--upTo-menu' + _buttonIndex + ' > a.navTrigger1'); if(_button.length) { _subHiddenButton = $('.navTrigger1-row-items li.menu ul.menu-list li.hide--downThrough-menu' + _buttonIndex + ' a'); _subHiddenButton.attr('href', _button.attr('href')).html(_button.html()); } else { $('.navTrigger1-row-items li.menu ul.menu-list li.hide--downThrough-menu' + _buttonIndex).remove(); } } $('header strong[data-handler="menu"]').removeClass('navTrigger1--selected'); if(_moreHighlight) { $('header strong[data-handler="menu"]').addClass('navTrigger1--selected'); } if(settings.userMenuDirect.pn) { var _menuElem = $('ul.userBar label.userBar-button--pm').removeAttr('data-menu').removeAttr('data-handler'); _menuElem.find('input').removeAttr('data-handler').click(function() { window.location.href = document.location.protocol + '//' + document.location.hostname + '/profile/' + userName + '/messages'; }); } if(settings.userMenuDirect.account) { var _menuElem = $('ul.userBar label.userBar-button--user').removeAttr('data-menu').removeAttr('data-handler'); _menuElem.find('input').removeAttr('data-handler').click(function() { window.location.href = document.location.protocol + '//' + document.location.hostname + '/profile/' + userName; }); } } function addCyberDealz() { var _newMenu = $('
  • ').addClass('hide--downThrough-').append($('').addClass('navMenu1-item').attr('href','http://www.mydealz.de/cyber-monday/cyberdeals').html('Cyber-Deals')).appendTo($('.navMenu--width-l').eq(0)); } function removeAds() { var _ads = {topBar: '.topBar', gsWidget: '#gs-widget', inside: "#side section[data-track=\"{\\\"category\\\":\\\"Banner Sidebar\\\"}\"]", nlSection: '.inline-newsletter, .newsletter', app: '[alt="app banner for ios android and window phone"]'}; for(_aInd in _ads) { if(_aInd in settings.hideAds && settings.hideAds[_aInd]) { if($(_ads[_aInd]) != null) { $(_ads[_aInd]).remove(); } } } } function addFuncLinks() { var _threads = $('div.thread, li.thread'); if(_threads.length) { $(_threads).each(function (_tInd, _tVal) { _thread = $(_tVal); var _list = _thread.find('footer ul'); var _author = $.trim(_thread.find(".thread-author").eq(0).text()); var _topic = $.trim(_thread.find(".thread-title h1").eq(0).text()); var _pnLink = $('
  • ').addClass('hList-item').append($('').click(startWaitForPN).addClass('link').addClass('ico').addClass('ico--type-pn-blue').html('PN').attr('data-modal', '{"endpoint":"http:\\/\\/www.mydealz.de\\/profile\\/' + userName + '\\/messages\\/modal-window?to=' + encodeURIComponent(_author) + '"}').attr('data-handler', 'modal').attr('href', 'http://hukd.mydealz.de/profile/' + userName + '/messages/compose-mail?to=' + encodeURIComponent(_author))); addGlobalStyle('.ico--type-pn-blue::before { background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAIAAAACUFjqAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAB/SURBVChTY/gPBm8+/Vh95N6kTVeACMgAciHiIOkbjz9oZ61FQ0BBkPTnb7+AnP2XniHLQbhAKYYTN14iCyEzgFIMQJsgHIgEsjFAKRRpNLTt9CMGZOVoCOg6hvsvPqGJwhHUY0C/okkAEVAQKg0Bz95+vXDvLdC1QAZU6P9/AKPpvjdJZe34AAAAAElFTkSuQmCC); background-size: 10px 10px; background-position: 3px 3px;}'); _list.append(_pnLink); var _reportLink = _thread.find('.ico--type-megaphone-blue').parent(); _newLink = $('
    ').addClass('hList-item').html('').find('button').attr('data-replace', '["/vote?v=spam&t=' + _thread.attr('id') + '", "div"]').parent(); _reportLink.before(_newLink); _newLink = $('
    ').addClass('hList-item').html('').find('button').attr('data-replace', '["/vote?v=expired&t=' + _thread.attr('id') + '", "div"]').parent(); _reportLink.before(_newLink); _reportLink.remove(); }); } } function startWaitForPN () { var _thread_id = $('div.thread, li.thread').has($(this)).attr('id'); timer.pn = window.setInterval(function () { waitForPN(_thread_id) }, 50); } function waitForPN(_thread_id) { if(!$('#' + _thread_id).find('.ico--type-pn-blue').hasClass('seal--spin')) { if('pn' in timer) { window.clearInterval(timer.pn); delete timer.pn; } $('#pm-subject').val($.trim($('#' + _thread_id + ' header.thread-head div.thread-title .inlineText').text())); saveRestorePN($.trim($('#' + _thread_id + ' header.thread-head .thread-meta a.thread-author').text()), _thread_id); } } function insertDirectLink() { // Direktlink by Nico // onClick entfernt $(".comments-list > li").each(function(_index) { var _directLink = document.location.protocol + '//' + document.location.hostname + document.location.pathname + '?page=' + $(".form--narrow input[name=cur_page]").val() +'#' + $(this).prop('id'); $(this).find(".hList:first").append("
  • "); }); } function addFeedbackButtons() { var _thread = $('div.thread'); if(_thread.length) { var _list = _thread.find('footer ul'); var _author = $.trim(_thread.find(".thread-author").eq(0).text()); if(filterPath() == 'kleinanzeigen' && $('div.thread').length) { if(_author == userName) { if(_list.find('.ico--type-follow-blue').length == 1) { _list.append($('
  • ').addClass('hList-item').html('').find('button').attr('data-popover',"{\"endpoint\":\"\\\/profile\\\/" + userName + "?get_feedback_form=1&tid=" + _thread.attr('id') + "\",\"position\":\"ne\"}")); } } else { _list = $('ul.comments-list li.comments-item').has('a.avatar-link[href="' + document.location.protocol + '//' + document.location.hostname + '/profile/' + userName + '"]'); if(!_list.find('.ico--type-follow-blue').length) { _list.find('footer ul.comment-options').append($('
  • ').addClass('comment-option hList-item').html('').find('button').attr('data-popover',"{\"endpoint\":\"\\\/profile\\\/" + userName + "?get_feedback_form=1&tid=" + _thread.attr('id') + "\",\"position\":\"ne\"}").parent()); } } } } } function markPnRead() { if(settings.userMenuDirect.pn) { $.ajax({ method: 'POST', url: 'http://www.mydealz.de/activity?type=pm', contentType: 'application/x-www-form-urlencoded', accept: 'application/json, text/javascript, */*', dataType: 'json' }).done(function () { $('#activities-count-pm').remove(); }); } } function filterPath() { _path = document.location.pathname.replace(/^\/(new|hot|discussed)$/, '/').replace(/^\/([^\/]+).*$/, '$1').replace(/(-?(new|discussed))?$/, ''); if(_path != '/' && !(_path in settings.fromTo)) { return false; } return _path; } function startWaitForSubmit() { timer.submit = window.setInterval(waitForSubmit, 50); } function waitForSubmit() { if(!$('#commentForm').eq(0).hasClass('seal--spin')) { if('submit' in timer) { window.clearInterval(timer.submit); delete timer.submit; } modifyComments(); addFeedbackButtons(); } } function startWaitForChange() { var _link = $(this); var _params = JSON.parse(_link.attr('data-replace'))[2]; timer['change_'+_params.comment_id] = window.setInterval(function() { waitForChange(_params.comment_id)}, 50); } function waitForChange(_comment_id) { if(!$('ul.comments-list #post' + _comment_id + ' div.comments-body').eq(0).hasClass('seal--spin')) { if(('change_'+_comment_id) in timer) { window.clearInterval(timer['change_'+_comment_id]); delete timer['change_'+_comment_id]; } $('ul.comments-list #post' + _comment_id + ' #commentEditForm-reason').attr('value', settings.comments.editReason).val(settings.comments.editReason); $('#commentEditForm-content-' + _comment_id).val($('#commentEditForm-content-' + _comment_id).val().replace(/\$/m, '')); } } function modifyComments() { var _changeLinks = $('ul.comments-list .ico--type-edit-blue').off('click', startWaitForChange).on('click', startWaitForChange); $('#commentForm').submit(startWaitForSubmit); if(settings.comments.useSignature) { _commentField = $('#commentForm-content'); if(_commentField.length && settings.comments.signature.length && _commentField.val().indexOf(settings.comments.signature) == -1) { _commentField.val(_commentField.val() + "\n" + settings.comments.signature); _commentField.setCursorPosition(0); } } var _quoteLinks = $('.ico--type-quote-blue'); if(_quoteLinks.length) { _quoteLinks.each(function (_qlInd, _qlVal) { var _quoteLink = $(_qlVal); _quoteLink.removeAttr('data-track').removeAttr('data-handler'); _quoteLink.click(grabQuote); }); } var _userAvatars = $('img.avatar-image--comment:not([data-popover*="/' + userName + '?"])'); if(_userAvatars.length) { _userAvatars.off('click', startWaitForUserCommentMenu).on('click', startWaitForUserCommentMenu); } } function startWaitForUserCommentMenu() { var _link = $(this); var _commentUser = _link.attr('data-popover').replace(/^.*profile\\\/([^\?]+)\?.*$/, '$1'); timer['userCommentMenu_'+_commentUser] = window.setInterval(function() { waitForUserCommentMenu(_commentUser)}, 50); } function waitForUserCommentMenu(_commentUser) { if($('#powerTip > div').hasClass('profile')) { if('userCommentMenu_' + _commentUser in timer) { window.clearInterval(timer['userCommentMenu_' + _commentUser]); delete timer['userCommentMenu_' + _commentUser]; } // attach Events on PN-Button $('#powerTip > div.profile ul.profile-column a.button').has('span.ico--type-mail-white').on('click', startWaitForCommentPN); } } function startWaitForCommentPN() { var _link = $(this); var _pnUser = _link.attr('href').replace(/^.*\?to=(.*)$/, '$1'); timer['pnWindow_'+_pnUser] = window.setInterval(function() { waitForCommentPN(_pnUser)}, 50); } function waitForCommentPN(_pnUser) { if(!$('#powerTip > div.profile ul.profile-column a.button').has('span.ico--type-mail-white').hasClass('seal--spin')) { if('pnWindow_' + _pnUser in timer) { window.clearInterval(timer['pnWindow_' + _pnUser]); delete timer['pnWindow_' + _pnUser]; } saveRestorePN(_pnUser); } } function savePN(_userPath) { save.pn[_userPath] = {message: $('#pm-message').val(), subject: $('#pm-subject').val()}; } function saveRestorePN(_pnUser, _thread_id, _initSave) { // attach Events on PN-Button var _userPath = _pnUser + (_thread_id != null ? '_' + _thread_id : ''); if(_userPath in save.pn) { $('#pm-subject').val(save.pn[_userPath].subject); $('#pm-message').val(save.pn[_userPath].message); } if(_initSave != null && _initSave) { savePN(_userPath); } $('#pm-subject, #pm-message').change(function() { savePN(_userPath); }); $('div.modalWin-body').has('#pm-message').find('form.form').submit(function () { if(_userPath in save.pn) { delete save.pn[_userPath]; } timer['pnSent_' + _userPath] = window.setInterval(function () { waitForPNSent(_pnUser, _thread_id) }, 50); }); } function waitForPNSent(_pnUser, _thread_id) { GM_log('Waiting for PN sent'); var _form = $('#template-modal .modalWin').has('#pm-subject').find('form.form'); if(!_form.hasClass('seal--spin')) { var _userPath = _pnUser + (_thread_id != null ? '_' + _thread_id : ''); if('pnSent_' + _userPath in timer) { window.clearInterval(timer['pnSent_' + _userPath]); delete timer['pnSent_' + _userPath]; } var _success = _form.find('.message').eq(0).hasClass('message--type-success'); GM_log('Gesendet: ' + _success); if(_success) { $('#template-modal .modalWin').html('').removeClass('modalWin'); $(document.body).removeClass('modal--active'); createMessageWindow('Nachricht verschickt!', 'success'); } else { saveRestorePN(_pnUser, _thread_id, true); } } } function grabQuote() { var _quoteLink = $(this); var _params = JSON.parse(_quoteLink.attr('data-comment-quote')); $.ajax({ method: 'POST', url: 'http://www.mydealz.de/comment?raw=1', contentType: 'application/x-www-form-urlencoded', accept: 'application/json, text/javascript, */*', data: 'comment_id=' + _params.commentId + '&thread_id=' + _params.threadId, dataType: 'json' }).done(function (_rdata) { if(typeof _rdata == 'object' && 'data' in _rdata && typeof _rdata.data == 'object' && 'comment_id' in _rdata.data) { var _comment = '[quote=' + _params.username + ']' + _rdata.data.content.replace(/\
    \[edit_reasons\][^]+\[\/edit_reasons\]/m, '') + '[/quote]'; // vom HUKD Toolkit (Danke an lolnickname) /* Zeilenwechsel entfernen */ _comment = _comment.replace(/^\s+$/g, ''); while(/\n\r?\n/m.test(_comment)) { _comment = _comment.replace(/\n\r?\n/m,"\n"); } /* mehrfache Leerzeichen */ while(/(\S)[^\S\r\n]{2,}(\S)/.test(_comment)) { _comment = _comment.replace(/(\S)[^\S\r\n]{2,}(\S)/g,"$1 $2"); } /* einzelne Leerzeichen nach BBCode */ _comment = _comment.replace(/quote(=([a-zA-Z0-9]+)?)?\]\s/g,"quote$1]"); /* einzelne Leerzeichen vor BBCode */ _comment = _comment.replace(/\s\[(\/)?quote/g,"[$1quote"); /* Leerzeichen an Anfang und Ende des Strings */ _comment = $.trim(_comment); _comment = maxQuotes(_comment); $('#commentForm-content').insertAtCaret(_comment); } }); } function maxQuotes(_quoteContent) { // vom HUKD Toolkit (Danke lolnickname) var _quoteStartPattern = /\[quote(=[0-9a-zA-Z_]+)?\]/g; var _quoteEndPattern = /\[\/quote\]/g; var _quoteStarts = _quoteContent.match(_quoteStartPattern); var _quoteEnds = _quoteContent.match(_quoteEndPattern); var _quoteStartCount = 0; var _quoteEndCount = 0; if (_quoteStarts && _quoteEnds) { _quoteStartCount = _quoteStarts.length; _quoteEndCount = _quoteEnds.length; } if (_quoteStartCount != _quoteEndCount) { alert("BBCodes fuer Zitate nicht eindeutig."); return _quoteContent; } /* maximale Ebenen */ /* mit 0 beginnend */ var _maxQuoteLevel = settings.comments.maxQuoteLevel; if (_quoteStartCount <= _maxQuoteLevel) { return _quoteContent; } var _startPos = new Array(); var _endPos = new Array(); var _positions = Array(); for (var _i = 0; _i < _quoteStartCount; _i++) { _positions.push({pos: _quoteContent.indexOf(_quoteStarts[_i], _startPos[_i-1] + 1), type: 'start', match: _quoteStarts[_i]}); _startPos[_i] = _quoteContent.indexOf(_quoteStarts[_i], _startPos[_i-1] + 1); _positions.push({pos: _quoteContent.indexOf(_quoteEnds[_i], _endPos[_i-1] + 1), type: 'end', match: _quoteEnds[_i]}); _endPos[_i] = _quoteContent.indexOf(_quoteEnds[_i], _endPos[_i-1] + 1); } delete _startPos; delete _endPos; var _curQuoteLevel = 0; var _reducedQuote = ''; var _startSnippet = 0; _positions.sort(function (_a, _b) { return _a.pos - _b.pos; }); for(_i = 0; _i < _positions.length; _i++) { if(_positions[_i].type == 'start') { if(_curQuoteLevel == _maxQuoteLevel) { _reducedQuote += _quoteContent.substring(_startSnippet, _positions[_i].pos); } _curQuoteLevel++; } else { _curQuoteLevel--; if(_curQuoteLevel == _maxQuoteLevel) { _startSnippet = _positions[_i].pos + _positions[_i].match.length; } } } _reducedQuote += _quoteContent.substr(_startSnippet); return _reducedQuote; } function addMenuSwitcher(_path) { addGlobalStyle('.enhancer-link-menuswitch { color: #ff0000 !important; }'); _path = filterPath(_path); if(!_path) { return; } var _menu = $('.navTrigger2-row .fGrid-last .menu:first'); if(_menu.length) { _menu.on('mouseenter', initMenuSwitch); _menu.on('mouseleave', stopMenuSwitch); } } function initMenuSwitch() { timer.menuSwitch = window.setTimeout(menuSwitch, 3000); } function menuSwitch() { var _menu = $('.navTrigger2-row .fGrid-last .menu:first'); _menu.find('li a.nav2Morph-link').addClass('enhancer-link-menuswitch').on('click', savePageChoice); _menu.find('li a.nav2Morph-link--selected').addClass('enhancer-link-menuswitch--selected'); } function savePageChoice() { var _elem = $(this); _path = filterPath(_path); if(!_path) { return; } settings.fromTo[_path] = _elem.attr('href').replace(document.location.origin + '/', ''); saveSettings(); } function stopMenuSwitch() { if('menuSwitch' in timer) { try { window.clearTimeout(timer.menuSwitch); } finally { delete timer.menuSwitch; } } var _menu = $('.navTrigger2-row .fGrid-last .menu:first'); _menu.find('.enhancer-link-menuswitch').removeClass('enhancer-link-menuswitch').removeClass('enhancer-link-menuswitch--selected').off('click', savePageChoice); } function modifyListings() { var _elems = $('li.thread'); if(_elems.length && settings.deals.hide.length) { _elems.each(function (_eInd, _eVal) { if((new RegExp(settings.deals.hide, 'i')).test($(_eVal).find('.thread-head .section-title-link').text())) { $(_eVal).remove(); } }); } } function addScrollUpButton() { var _newElem = $('').attr('id', 'scrollUpButton').append($('
    ').addClass('tGrid tGrid tGrid--auto').append($('').attr('href', _img.attr('src').replace("threads/", "threads/high-res/")).attr('target', '_blank'); _link.appendTo(_img.parent()).append(_img); _link.click(zoomImage); }); } var _imgLinks = $('a.imageFrame'); _imgLinks.click(zoomImage); } function zoomImage(_evt) { _evt.preventDefault(); _evt.stopPropagation(); var _link = $(this); var _container = $('
    ').attr('style', 'position: fixed; left: 0; right: 0; top: 0; bottom: 0; z-index: 99; background-color: rgba(68,68,68,0.5); white-space: nowrap; text-align: center; margin: 0;').appendTo($(document.body)).append($('').attr('style', 'display: inline-block; height: 100%; vertical-align: middle;')).append($('').attr('src', _link.attr('href')).attr('style', 'vertical-align: middle; max-height: ' + ($(window).height() - 2) + 'px; max-width: ' + ($(window).width() - 2) + 'px; border-radius: 5px; border: 1px solid #ffffff;')); _container.click(function () { $(this).remove();}); } function addDealLinks() { // Danke an vielleichtmann1 für die Idee var _thread = $('div.thread div.thread-body div.section-sub').eq(0); if(_thread.length) { _thread.html(_thread.html().replace(/([^\";=])(https?:\/\/[^ ]+?)(\n|\|\s)/g, '$1$2$3')); } } function retrieveUserName() { try { userName = $('.userBar-userCenter-menu .avatar-frame').parent().html().replace(/(\r|\n)/g, '').replace(/^.*\\\/profile\\\/([^\\\<\>]+)\\\/ajax.*$/, '$1'); } catch (e) { window.location.href = 'https://www.mydealz.de/login'; } } function addGlobalStyle(_css) { var _head, _style; _head = document.getElementsByTagName('head')[0]; if (!_head) { return; } _style = document.createElement('style'); _style.type = 'text/css'; _style.innerHTML = _css; _head.appendChild(_style); } function loadSettings() { var _verbose = false; var _lSettings = JSON.parse(GM_getValue('settings', '{}')); var _sprop; // sinnvolleren, rekursiven Parser schreiben for (var _prop in defaultSettings) { if(_prop in _lSettings) { settings[_prop] = _lSettings[_prop]; } else { settings[_prop] = defaultSettings[_prop]; } if(_verbose) { GM_log(_prop + ': ' + settings[_prop]); } for(_sprop in defaultSettings[_prop]) { if(typeof _lSettings[_prop] == 'object' && _sprop in _lSettings[_prop]) { settings[_prop][_sprop] = _lSettings[_prop][_sprop]; } else { settings[_prop][_sprop] = defaultSettings[_prop][_sprop]; } if(_verbose) { GM_log(_prop + '.' + _sprop + ': ' + settings[_prop][_sprop]); } } } } function addSetupLink() { var _newMenu = $('
  • ').addClass('hide--downThrough-').attr('id', 'mydealz-enhancer-setup--link').append($('').addClass('navMenu1-item').attr('href','#mydealz-enhancer').html('MyDealz-Enhancer')).appendTo($('.navMenu--width-l').eq(0)); _newMenu.find('a').click(showSetup); } function saveSettings() { GM_setValue('settings', JSON.stringify(settings)); } function showSetup() { document.title = 'MyDealz-Enhancer Einstellungen'; $('strong[data-handler="menu"]').parent().parent().removeClass('menu--active'); $('.navTrigger1--selected, .navMenu1-item--selected').removeClass('navTrigger1--selected navMenu1-item--selected'); $('#mydealz-enhancer-setup--link').addClass('navMenu1-item--selected'); $('.navTrigger2-row').remove(); $('.page-canvas > section').eq(0).remove(); $('div.page-canvas:first > div.page-content').html('
    '); $('#main').html('').attr('class', 'content-main content-background').html('

    Bearbeite Deine MyDealz-Enhancer Einstellungen

  • '); var _sections = $('#main .section--padded'); var _form = $('#main form.form'); _form.submit(submitSettings); var _section = $('
    ').addClass('section-sub').html('

    Info und Diskussionsthread

    Informationen und Verbesserungsvorschläge im MyDealz-Enhancer-Thread.'); _section.appendTo(_sections); _section = $('

    ').addClass('section-sub').html('

    Enhancer Verhalten

    '); _section.appendTo(_sections); for(var _sInd in settings.behavior) { if(settings.behavior[_sInd]) { _section.find('#behaviorForm-behavior_' + _sInd).prop('checked', 'checked').attr('checked', 'checked'); } else { _section.find('#behaviorForm-behavior_' + _sInd).prop('checked', false).removeAttr('checked'); } } _section = $('
    ').addClass('section-sub').html('

    Werbung ausblenden

    '); _section.appendTo(_sections); for(var _sInd in settings.hideAds) { if(settings.hideAds[_sInd]) { _section.find('#adForm-hideAds_' + _sInd).prop('checked', 'checked').attr('checked', 'checked'); } else { _section.find('#adForm-hideAds_' + _sInd).prop('checked', false).removeAttr('checked'); } } _section = $('
    ').addClass('section-sub').html('

    Buttons im Hauptmenu

    '); _section.appendTo(_sections); for(var _sInd in settings.moveButtons) { if(settings.moveButtons[_sInd]) { _section.find('#buttonForm-moveButtons_' + _sInd).prop('checked', 'checked').attr('checked', 'checked'); } else { _section.find('#buttonForm-moveButtons_' + _sInd).prop('checked', false).removeAttr('checked'); } } _section = $('
    ').addClass('section-sub').html('

    UserMenu Direktlinks

    '); _section.appendTo(_sections); for(var _sInd in settings.userMenuDirect) { if(settings.userMenuDirect[_sInd]) { _section.find('#userMenuForm-direct_' + _sInd).prop('checked', 'checked').attr('checked', 'checked'); } else { _section.find('#userMenuForm-direct_' + _sInd).prop('checked', false).removeAttr('checked'); } } _section = $('
    ').addClass('section-sub').html('

    Deals/Gutscheine/…

    '); _section.appendTo(_sections); for(var _sInd in settings.deals) { _section.find('#dealsForm-deals_' + _sInd).val(settings.deals[_sInd]).attr('value', settings.deals[_sInd]); } _section = $('
    ').addClass('section-sub').html('

    Kommentieren

    • ' + (settings.comments.useSignature ? '
    • ' : '') + '
    '); _section.appendTo(_sections); for(var _sInd in settings.comments) { if(_section.find('#commentForm-comments_' + _sInd).length) { switch(typeof settings.comments[_sInd]) { case 'boolean': if(settings.comments[_sInd]) { _section.find('#commentForm-comments_' + _sInd).prop('checked', 'checked').attr('checked'); } else { _section.find('#commentForm-comments_' + _sInd).prop('checked', false).removeAttr('checked'); } default: _section.find('#commentForm-comments_' + _sInd).val(settings.comments[_sInd]).attr('value', settings.comments[_sInd]); break; } } } _section.find('ul').append($('
  • ').addClass('form-list-row').html('
    ')); } function createMessageWindow(_text, _type) { var _messageList = $('#globalMsg .globalMsg-list'); $('
  • ').addClass('globalMsg-item globalMsg-item--type-success message message--type-success').html('
  • ' + _text + '
  • ').appendTo(_messageList); window.setTimeout(function () { try { _messageList.find('li').remove(); } catch(e) { } }, 8000); } function submitSettings(_evt) { _evt.preventDefault(); _evt.stopPropagation(); var _errMessage = ''; var _allOK = true; for(var _sInd in settings.behavior) { try { settings.behavior[_sInd] = $('#behaviorForm-behavior_' + _sInd).prop('checked'); } catch(e) { _allOK = false; } } for(var _sInd in settings.hideAds) { try { settings.hideAds[_sInd] = $('#adForm-hideAds_' + _sInd).prop('checked'); } catch(e) { _allOK = false; } } for(var _sInd in settings.moveButtons) { try { settings.moveButtons[_sInd] = $('#buttonForm-moveButtons_' + _sInd).prop('checked'); } catch(e) { _allOK = false; } } for(var _sInd in settings.userMenuDirect) { try { settings.userMenuDirect[_sInd] = $('#userMenuForm-direct_' + _sInd).prop('checked'); } catch(e) { _allOK = false; } } for(var _sInd in settings.deals) { if(_sInd == 'hide') { try { new RegExp($('#dealsForm-deals_' + _sInd).val()); } catch (e) { _errMessage += e + '
    '; _allOK = false; } } try { settings.deals[_sInd] = ($('#dealsForm-deals_' + _sInd).attr('type') == 'number' ? parseInt($('#dealsForm-deals_' + _sInd).val(), 10) : $('#dealsForm-deals_' + _sInd).val()); } catch(e) { _allOK = false; } } for(var _sInd in settings.comments) { if($('#commentForm-comments_' + _sInd).length) { try { settings.comments[_sInd] = ($('#commentForm-comments_' + _sInd).attr('type') == 'number' ? parseInt($('#commentForm-comments_' + _sInd).val(), 10) : $('#commentForm-comments_' + _sInd).val()); } catch(e) { _allOK = false; } } } if(_allOK) { saveSettings(); createMessageWindow('Deine Einstellungen wurden gespeichert.
    Seite neu laden zum Anwenden.', 'success'); } else { createMessageWindow('Ein Fehler trat beim Speichern auf.' + (_errMessage.length ? '
    ' + _errMessage : ''), 'error'); } } function init() { var _noError = true; try { var _path = document.location.pathname.replace(/^\/([^\?]+).*$/, '$1'); if(/^(visit|image)/.test(_path) || /^JavaScript Shell/.test(document.title)) { return; } retrieveUserName(); loadSettings(); addMenuSwitcher(filterPath()); remodelNavBar(); removeAds(); addCyberDealz(); addSetupLink(); changeLinks(); if(document.location.hash == '#mydealz-enhancer') { showSetup(); } switch(_path) { case 'cyber-monday/cyberdeals': addTimes(); case 'profile/' + userName + '/messages': markPnRead(); } modifyListings(); addScrollUpButton(); addImageZoom(); insertDirectLink(); addFeedbackButtons(); addFuncLinks(); modifyComments(); addDealLinks(); } catch (e) { alert(e); _noError = false; } // Danke an lolnickname für die Idee if(_noError) { if(settings.behavior.showGreenDots) { $('.userBar-link .avatar-image').css('border', '1px dotted #00ff00'); } } else { $('.userBar-link .avatar-image').css('border', '1px dotted #aa0000'); } } init(); } // Erst laden, wenn DOM fertig ist if(document.readyState == 'interactive') { ModifyPage(); } else { $(document).ready(ModifyPage); }