<!-- modulation buttons script -->
<script type="text/javascript">
var modulationSelector = 'span[style*="color: #ff0000"]';
var photoSelector = '.entry pre img';
var modulationCounter = 0;
$(document).ready(function() {
if ($(modulationSelector).length && !($(photoSelector).length)) {
$('.modulation_block').show();
}
$('.modulation_increment').click(function(){moveChords(1);});
$('.modulation_decrement').click(function(){moveChords(0);});
});
function moveChords(isUp)
{
modulationCounter = modulationCounter + (isUp ? 1 : -1);
var counterElements = $('.modulation_counter');
if (counterElements.length) {
counterElements[0].textContent = modulationCounter;
}
console.log('moving chords ' + (isUp ? 'up' : 'down'));
$(modulationSelector).each(function() {
this.textContent = moveChordRow(this.textContent, isUp);
});
}
function moveChordRow(chordRow, isUp)
{
var firstSpaceMatch = chordRow.match(/^([\s\n]*).*(\n\s*)?$/);
var resultString = firstSpaceMatch[1];
var pattern = /[^\s\n]+(?:\s+|$)/g;
var matches;
while (null !== (matches = pattern.exec(chordRow))) {
resultString += moveChordBlock(matches[0], isUp);
}
return resultString + (firstSpaceMatch[2] ? firstSpaceMatch[2] : '');
}
function moveChordBlock(chordString, isUp)
{
var matches = chordString.match(/([A-H]#?)([^\s\/]*)\/?([A-H]?#?)([^\s]*)(\s*)/);
if (null === matches) {
return chordString;
}
var oldChord = matches[1];
var modifiers = matches[2];
var secondChord = matches[3];
var hasSecondChord = secondChord.length > 0;
var secondModifiers = matches[4];
var spacesCount = matches[5].length;
var newChord = moveChord(oldChord, isUp);
var newSecondChord = hasSecondChord ? moveChord(secondChord, isUp) : null;
if (null === newChord || (hasSecondChord && null === newSecondChord)) {
console.error('Cannot parse chord string: ' + chordString);
return chordString;
}
spacesCount = spacesCount + oldChord.length - newChord.length + (hasSecondChord ? secondChord.length - newSecondChord.length : 0);
spacesCount = (spacesCount > 1 ? spacesCount : 1);
return newChord + modifiers + (hasSecondChord ? '/' + newSecondChord + secondModifiers : '') + ' '.repeat(spacesCount);
}
function moveChord(chord, isUp) {
var chords = ['A', 'B', 'H', 'C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#'];
var index = chords.indexOf(chord);
if (-1 === index) {
return null;
}
return chords[ (index + chords.length + (isUp ? 1 : -1)) % chords.length ];
}
</script>
<!-- end of modulation buttons script -->
Может в ускорении поможет смена шаблона? Но в этом случае все может захромать...
Пример: нужно спарсить новости, список которых находится на site.ru/news/, а урл детальной новости имеет вид site.ru/nazvanie-novosti/. То есть отсутствует общий признак в URL