User:Aseerel4c26/osm.org UI fixes by JS

From OpenStreetMap Wiki
Jump to: navigation, search
  • no guarantee for anything
  • WTFPL
  • always look in the history of this page to spot malicious edits if you want to use the snippet
  • use as described there
  • improvement suggestions are welcome on the talk page

run before pageload @www.openstreetmap.org

function setCookie(name, value, expstring) {
    var expires;
    if (expstring) {
        expires = '; expires=' + expstring;
    } else {
        expires = '';
    }
    document.cookie = encodeURIComponent(name) + '=' + encodeURIComponent(value) + expires + '; path=/';
}

function getCookie(name) {
    var nameEsc = encodeURIComponent(name);
    var cookieArr = document.cookie.split(';');
    var content = null;
    var found = false;
    for (var i = 0; !found && i < cookieArr.length; i++) {
        if (trim(cookieArr[i].split('=')[0]) === nameEsc) {
            found = true;
            content = decodeURIComponent(trim(cookieArr[i].split('=')[1]));
        }
    }
    return content;
}

function trim(text) {
    return text.replace(/(^\s+|\s+$)/g, '');
}

function removeDNFromCookie() {
    var oldcookie = getCookie('_osm_location');
    var newcookielayerparams = oldcookie.split('|')[3];
    newcookielayerparams = newcookielayerparams.replace(/[DN]/g, '');
    newcookie = oldcookie.split('|')[0] + '|' + oldcookie.split('|')[1] + '|' + oldcookie.split('|')[2] + '|' + newcookielayerparams;
    var newexpdate = new Date;
    newexpdate.setYear(newexpdate.getFullYear() + 10);
    setCookie('_osm_location', newcookie, newexpdate);
}

removeDNFromCookie();

run after pageload !@www.openstreetmap.org/

if (document.location.href.split('#')[0].split('/').length > 4) {
    $("div#sidebar_content div.details abbr").each(function () {
        $(this).replaceWith("<ul><li>" + $(this).attr("title").replace("\n", "</li>\n<li>") + "</li></ul>");
    });
    $("div#sidebar_content li").css("list-style-type", "disc");
    $('#sidebar_content .browse-tag-list .browse-tag-k').css({'width':'45%'}); 
    $('#sidebar_content .browse-tag-list .browse-tag-v').css({'width':'55%'});
    if (document.location.href.split('#')[0].split('/')[3] === 'node') {
        $("div#sidebar_content div.geo a").each(function () {
            $(this).attr("href", $(this).attr("href").replace(/^\/#map=([0-9]*)\/([0-9]+\.?[0-9]*)\/([0-9]+\.?[0-9]*)$/, "/?zoom=$1&mlat=$2&mlon=$3"));
        });
        $("div#sidebar_content div.geo .latitude").each(function () {
            $(this).html($(this).html().replace(",", "."));
        });
        $("div#sidebar_content div.geo .longitude").each(function () {
            $(this).html($(this).html().replace(",", "."));
        });
    }

    if (document.location.href.split('#')[0].split('/')[3] === 'changeset') {
      $('#sidebar_content div.browse-section h4').first().css({"border":"1px solid #DDDDDD" , "padding":"5px"});
      $('#sidebar_content .browse-tag-list .browse-tag-k').css({'width':'35%'}); 
      $('#sidebar_content .browse-tag-list .browse-tag-v').css({'width':'65%'});

	 var TheCommentsHeader = $('#sidebar_content .browse-section .comments-header');
	 if ($(".changeset-comments").length > 0) {
	   TheCommentsHeader.css("background-color", "#FFFF66");
	 } else {
	   var DiscussionSection = $('<div></div>');
	   var TheCommentsRest = TheCommentsHeader.nextUntil('h4'); 
	   TheCommentsHeader.appendTo(DiscussionSection);
	   TheCommentsRest.appendTo(DiscussionSection);
	   DiscussionSection.appendTo($('#sidebar_content'));
	 }
    }
}