Skip to content

Instantly share code, notes, and snippets.

@GoSubRoutine
Last active September 13, 2021 15:29
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save GoSubRoutine/33ba95eb188bbb6cd04e96e2d950b02b to your computer and use it in GitHub Desktop.
loadXML() from SuggestQueries.Google.com via Proxy
height: 300
scrolling: yes
border: yes
<script async src=https://cdn.JsDelivr.net/npm/p5></script>
<script defer src=sketch.js></script>
<?xml version="1.0"?><toplevel><CompleteSuggestion><suggestion data="hey google"/></CompleteSuggestion><CompleteSuggestion><suggestion data="hey dude shoes"/></CompleteSuggestion><CompleteSuggestion><suggestion data="hey dudes"/></CompleteSuggestion><CompleteSuggestion><suggestion data="hey"/></CompleteSuggestion><CompleteSuggestion><suggestion data="hey arnold"/></CompleteSuggestion><CompleteSuggestion><suggestion data="hey there delilah"/></CompleteSuggestion><CompleteSuggestion><suggestion data="hey there delilah lyrics"/></CompleteSuggestion><CompleteSuggestion><suggestion data="hey ya lyrics"/></CompleteSuggestion><CompleteSuggestion><suggestion data="hey siri"/></CompleteSuggestion><CompleteSuggestion><suggestion data="hey ya"/></CompleteSuggestion></toplevel>
/**
* loadXML() from SuggestQueries.Google.com via Proxy (v1.0.0)
* Andreas_Ref & GoToLoop (2021-Sep-13)
*
* https://Discourse.Processing.org/t/issue-loading-xml-feed-in-p5js/8212/11
*
* https://Bl.ocks.org/GoSubRoutine/33ba95eb188bbb6cd04e96e2d950b02b
*
* https://SuggestQueries.Google.com/complete/search?output=toolbar&hl=dk&q=hey
*
* https://Gist.GitHub.com/jimmywarting/ac1be6ea0297c16c477e17f8fbe51347
*/
"use strict";
const
HTTP = 'https://',
PROX = 'CorsAnywhere.HerokuApp.com/', MODE = '',
SITE = 'SuggestQueries.Google.com/', FOLD = 'complete/',
QRY = 'search?output=toolbar&hl=dk&q=hey',
LINK = HTTP + PROX + MODE + HTTP + SITE + FOLD + QRY,
FILE = 'search.xml', REMOTE = false,
CHILDREN = 'CompleteSuggestion', CHILD = 'suggestion', ATTRIB = 'data',
LIST = 'ol', ITEM = 'li',
titles = [];
let xml;
function preload() {
console.info(LINK);
xml = loadXML(REMOTE && LINK || FILE, print, console.warn);
}
function setup() {
noCanvas(), noLoop();
const children = xml.getChildren(CHILDREN);
for (const child of children)
titles.push(child.getChild(CHILD).getString(ATTRIB));
const ol = createElement(LIST)
.style('color', 'blue')
.style('font-weight: bold')
.style('font-size: 1.2em');
for (const title of titles) createElement(ITEM, title).parent(ol);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment