Created
February 7, 2017 06:36
-
-
Save aalexeev239/3643fef99dd85cc2b0792a5daca4ee20 to your computer and use it in GitHub Desktop.
swagger search bookmarklet
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
javascript:(function(){ | |
function findByText(text) { | |
let resources = {}; | |
const allItems = Array.prototype.slice.call(document.querySelectorAll('.resource .endpoint .operation .heading .path a')); | |
const items = allItems.filter((item) => { | |
return item.textContent.indexOf(text) >= 0; | |
}); | |
items.forEach((item) => { | |
const resource = item.closest('.resource'); | |
if (resource && !resource.classList.contains('active')) { | |
resources[resource.id] = resource; | |
} | |
}); | |
Object.keys(resources).forEach((key) => { | |
const link = resources[key].querySelector('.heading h2 a'); | |
link.click(); | |
}); | |
const offsetTop = Object.keys(resources).reduce(function(acc, curr) { | |
const resource = resources[curr]; | |
return Math.min(acc, resource.offsetTop); | |
}, Infinity); | |
setTimeout(function() { | |
if (isFinite(offsetTop)) { | |
window.scrollTo(0, offsetTop); | |
} else { | |
alert('Ничего не найдено'); | |
} | |
}, 500); | |
} | |
var text = window.prompt('Введите строку поиска'); | |
findByText(text); | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Скрипт реализует поиск по методам. Вводите строку поиска, находятся и раскрываются все соответствующие разделы.
Вставляется как букмарклет. Cоздайте новую закладку в браузере и вместо адреса скопируйте содержимое файла. Потом кликните по закладке, находясь на странице сваггера.