Last active
March 28, 2025 11:48
-
-
Save borissov/f488d2ae51648e66cdf4169ef53edf78 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| if(window.location.host === 'www.imot.bg'){ | |
| document.querySelector('a.next').style.width = '30%'; | |
| document.querySelector('a.prev').style.width = '30%'; | |
| console.log('cjs working'); | |
| } | |
| if(window.location.host === 'www.strava.com'){ | |
| function calculateAndAddCalories(htmlString) { | |
| const distanceMatch = htmlString.match(/<strong>([\d.]+)<abbr class="unit" title="kilometers"> km<\/abbr><\/strong>/); | |
| const timeMatch = htmlString.match(/<strong>([\d:]+)<\/strong>\s*<div class="label">\s*<span class="glossary-link run-version"/); | |
| const speedMatch = htmlString.match(/<td>([\d.]+)<abbr class="unit" title="kilometers per hour"> km\/h<\/abbr><\/td>/); | |
| if (!distanceMatch || !timeMatch || !speedMatch) { | |
| console.error("Parse failed."); | |
| return htmlString; | |
| } | |
| const distance = parseFloat(distanceMatch[1]); | |
| const timeString = timeMatch[1]; | |
| const speed = parseFloat(speedMatch[1]); | |
| const timeParts = timeString.split(":"); | |
| let hours = 0; | |
| let minutes = 0; | |
| let seconds = 0; | |
| if (timeParts.length === 3) { | |
| hours = parseInt(timeParts[0]); | |
| minutes = parseInt(timeParts[1]); | |
| seconds = parseInt(timeParts[2]); | |
| } else if (timeParts.length === 2) { | |
| minutes = parseInt(timeParts[0]); | |
| seconds = parseInt(timeParts[1]); | |
| } | |
| const totalHours = hours + minutes / 60 + seconds / 3600; | |
| const weight = 112; | |
| let met = 6; | |
| if (speed > 15) { | |
| met = 8; | |
| } | |
| const calories = met * weight * totalHours; | |
| const caloriesLi = `<li><strong>${calories.toFixed(2)} kcal</strong><div class="label">Calories</div></li>`; | |
| const ulIndex = htmlString.indexOf('<ul class="inline-stats section">'); | |
| if (ulIndex !== -1) { | |
| const ulEndIndex = htmlString.indexOf('</ul>', ulIndex) + '</ul>'.length; | |
| const newHtmlString = htmlString.slice(0, ulEndIndex - '</ul>'.length) + caloriesLi + '</ul>' + htmlString.slice(ulEndIndex); | |
| return newHtmlString; | |
| } | |
| return htmlString; | |
| } | |
| const activityStatsDiv = document.querySelector('.spans8.activity-stats'); | |
| if (activityStatsDiv) { | |
| const updatedHtml = calculateAndAddCalories(activityStatsDiv.innerHTML); | |
| activityStatsDiv.innerHTML = updatedHtml; | |
| } | |
| console.log('cjs working'); | |
| } | |
| //Remove transperent wrapper in instagram and force to HQ images. | |
| if(window.location.host === 'www.instagram.com'){ | |
| document.addEventListener('click', function(element){ | |
| if(element.srcElement.nodeName === 'DIV') | |
| { | |
| element.srcElement.parentElement.querySelectorAll('div img[src]').forEach(function(image){ | |
| let parentElementDivs = image.parentElement.parentElement; | |
| if(parentElementDivs.querySelectorAll('div').length == 2) | |
| { | |
| parentElementDivs.querySelector('div:last-child').remove(); | |
| } | |
| if(image.getAttribute('sizes') !== '10000px') | |
| { | |
| image.setAttribute('sizes','10000px'); | |
| } | |
| }); | |
| } | |
| }) | |
| console.log('cjs working'); | |
| } | |
| //Bitbucket VIM button | |
| if(window.location.host.includes('bitbucket.projects')){ | |
| let testUrl = window.location.href; | |
| let buttons = document.getElementsByClassName('secondary'); | |
| let vim_button = document.getElementsByClassName('vim-button'); | |
| if( | |
| testUrl.indexOf('/browse/') > -1 && | |
| buttons.length && | |
| !vim_button.length | |
| ) | |
| { | |
| let div = document.createElement("div"); | |
| let button_new = document.createElement("button"); | |
| button_new.classList.add('aui-button'); | |
| button_new.classList.add('vim-button'); | |
| button_new.innerHTML = 'VIM'; | |
| button_new.addEventListener("click", function(){ | |
| let line = 1; | |
| let url = window.location.href; | |
| //get line number | |
| if(url.indexOf('#') > -1) | |
| { | |
| [url, line] = url.split('#'); | |
| } | |
| //clear url params | |
| if(url.indexOf('?') > -1) | |
| { | |
| url = url.split('?')[0]; | |
| } | |
| let file_path = url.replace(/.*repos/,'/Users/radoslavborisov/www').replace('/browse',''); | |
| window.open('mvim://open?url=file://'+file_path+'&line='+line,'_blank'); | |
| }); | |
| div.classList.add('aui-buttons'); | |
| div.appendChild(button_new); | |
| buttons[0].prepend(div); | |
| } | |
| console.log('cjs working'); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment