Skip to content

Instantly share code, notes, and snippets.

@oboenikui
Created January 30, 2016 20:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oboenikui/02a301c24f2a712ee256 to your computer and use it in GitHub Desktop.
Save oboenikui/02a301c24f2a712ee256 to your computer and use it in GitHub Desktop.
Cookpadで材料を指定するもメニューが多すぎて選びきれないときに勝手に選んでくれるやつ
function parseQuery(query) {
var result = {};
var vars = query.split('&');
for (var i = 0; i < vars.length; i++) {
var pair = vars[i].split('=');
result[decodeURIComponent(pair[0])] = decodeURIComponent(pair[1]);
}
return result;
}
var params = parseQuery(__load_parameters);
var selected = ~~(Math.random() * params.rh);
$.get(`${location.origin + location.pathname}?page=${selected/10}&recipe_hit=${params.rh}`, function(data){
var div = document.createElement("div");
div.innerHTML = data
div.getElementsByClassName("recipe-title font13")[selected % 10].click();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment