Skip to content

Instantly share code, notes, and snippets.

@aalexeev239
Created February 7, 2017 06:36
Show Gist options
  • Save aalexeev239/3643fef99dd85cc2b0792a5daca4ee20 to your computer and use it in GitHub Desktop.
Save aalexeev239/3643fef99dd85cc2b0792a5daca4ee20 to your computer and use it in GitHub Desktop.
swagger search bookmarklet
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);
})()
@aalexeev239
Copy link
Author

aalexeev239 commented Feb 7, 2017

Скрипт реализует поиск по методам. Вводите строку поиска, находятся и раскрываются все соответствующие разделы.

Вставляется как букмарклет. Cоздайте новую закладку в браузере и вместо адреса скопируйте содержимое файла. Потом кликните по закладке, находясь на странице сваггера.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment