Skip to content

Instantly share code, notes, and snippets.

@GoSubRoutine
Last active November 8, 2019 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GoSubRoutine/f13a55e7cfaabea6aa6bdf028c1f2f1e to your computer and use it in GitHub Desktop.
Save GoSubRoutine/f13a55e7cfaabea6aa6bdf028c1f2f1e to your computer and use it in GitHub Desktop.
JSON Wikipedia CORS Origin
height: 260
scrolling: yes
border: yes
license: cc-by-4.0
<!DOCTYPE html>
<meta charset=utf-8>
<meta name=viewport content=width=device-width,initial-scale=1>
<script async src=https://cdn.JsDelivr.net/npm/p5></script>
<script defer src=sketch.js></script>
/**
* JSON Wikipedia CORS Origin (v1.1.2)
* GoToLoop (2019-Jan-21)
*
* https://Discourse.Processing.org/t/issue-with-loadjson/7682/4
* https://Bl.ocks.org/GoSubRoutine/f13a55e7cfaabea6aa6bdf028c1f2f1e
*/
"use strict";
const HTTP = 'https://', SITE = 'en.Wikipedia.org',
FOLD = '/w/', FILE = 'api.php',
ASK = '?', AND = '&',
ORI = 'origin=*',
ACT = 'action=opensearch',
WORD = 'search=unicorn',
LINK = HTTP + SITE + FOLD + FILE + ASK + ORI + AND + ACT + AND + WORD,
LIST = 'ol', ITEM = 'li', BLANK = '_blank', COLOR = 'Red';
let jsonArray;
function preload() {
print(LINK);
jsonArray = loadJSON(LINK, print);
}
function setup() {
noCanvas(), noLoop();
console.table(jsonArray);
const list = createElement(LIST)
.style('color', COLOR)
.style('font-weight: bold')
.style('font-size: 1.2em');
for (const url of jsonArray[3])
createElement(ITEM).child(createA(url, url, BLANK)).parent(list);
//createElement(ITEM, url.link(url)).parent(list);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment