Answer the question
In order to leave comments, you need to log in
How in my case to ennoble the code, make it more beautiful, without ruining the logic?
I'm testing the history, everything seems to be working, a demo for testing at
www.dulsky.eu/v/6sPiPA4ogwA
The history is updated at the bottom, you look and switch the history, even with a browser.
But being a js coder, I wanted to ask how to ennoble the code, make it more beautiful without ruining the logic? (JSON.stringif allows you to load from anywhere and anything, but it's just a string.
history.pushState(\''.$videoId.'\', null, \''.$videoId.'\') ;
where videoId could be a JSON feed)var i = 0;
(function(history)
{ var pushState = history.pushState;
history.pushState = function(state)
{ if
(typeof history.onpushstate == "function")
{history.onpushstate({state: state});}
return pushState.apply(history, arguments); }})
(window.history);
window.onpopstate = history.onpushstate = function(e)
{
i++; test=JSON.stringify(e.state);
var reg_pusto = test;
if (reg_pusto.length>10)
{ test =test.replace(/"/g,"");
loc =window.location.pathname;
loc = loc.substr(3,52);
loc =loc.replace(/=list=/g,"&list=");
locris = loc.substr(0,11);
if (locris.length<11) {locris2=''}
else
{ locris2= '<span onclick="ytplayer.loadVideoById(\''+loc+ '\', 0);return false"><img src="https://i1.ytimg.com/vi/'+ locris + '/default.jpg" align="left" width="120" height="70"></span>' };
if (test==loc) { test2= ' ' ;}
else
{ test2='<span onclick="ytplayer.loadVideoById(\''+ test + '\', 0);return false"><img src="https://i1.ytimg.com/vi/'+ test + '/default.jpg" align="right" width="120" height="70"></span>' ; };
$('#ms').html(''+ test2 + ''+i+''+ locris2 + ''); }
else{ };};
Answer the question
In order to leave comments, you need to log in
I don't know js, but I'll tell you the general principles of refactoring.
1) cover changing code with tests
2) eliminate duplication, one at a time
3) eliminated, run tests
4) continue until code is satisfied
You need to learn how to write code according to style, according to its structure in order to support and understand the code itself. And do not torment your eyes in a mess of symbols.
en.wikipedia.org/wiki/%D0%A1%D1%82%D0%B0%D0%BD%D0%...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question