123

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <head>
  <script src="https://brechtvdv.github.io/demo-data/comunica-logger.js"></script>
  <script src="https://brechtvdv.github.io/demo-data/comunica-browser.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/clusterize.js/0.18.0/clusterize.min.js"></script>
  <script src='//cdn.jsdelivr.net/npm/yasgui-yasqe@2.11.22/dist/yasqe.bundled.min.js'></script>

  <link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/clusterize.js/0.18.0/clusterize.min.css">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
  <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.8.2/css/all.css" integrity="sha384-oS3vJWv+0UjzBfQzYUhtDYW+Pj2yciDJxpsK1OYPAYjqT085Qq/1cq5FLXAZQ7Ay" crossorigin="anonymous">
  <link rel="stylesheet" href="https://brechtvdv.github.io/demo-data/ldf-client.css">
  <link href='//cdn.jsdelivr.net/npm/yasgui-yasqe@2.11.22/dist/yasqe.min.css' rel='stylesheet' type='text/css'/>

</head>
<body>

<h2>View your website as a spreadsheet</h2>

<label for="url">Enter URL of a webpage containing JSON-LD snippets</label>
</br>
</br>
    <input type="text" name="url" id="urlInput" value="https://hetarchief.be/nl/media/le-bruxellois-journal-quotidien-indépendant/zsYcSJRZZqIZlNsdSlk0dvuv"> 
<br/><br/>   

<div>
<button id="startbutton" onclick="fetchRecords()">Generate</button>
<div class="showquerytooltip" id="showquerytooltip">
  <span class="showquerytooltiptext">Show SPARQL query</span>
  <a id="showquerybutton" onclick="showquery()"><img src="https://brechtvdv.github.io/demo-data/sparql.png" alt="SPARQL" id="sparqlimg"></a>
</div>
  <i id="loader" class="fa fa-refresh fa-spin" style="font-size:24px"></i>
</div>

<div id="queryBlock">
  <br>
  <label for="query">Query</label>
  <br>
  <textarea id="query" rows="9" cols="100">
  SELECT * WHERE { 
    GRAPH ?document {
     ?newspaper a <http://schema.org/Newspaper> . 
     ?newspaper <http://schema.org/datePublished> ?datePublished . 
     ?newspaper <http://purl.org/dc/terms/title> ?title . 
     ?newspaper <http://schema.org/publisher> ?publisher . 
    }
  }
  </textarea>
</div>

<br> 
<label for="result">Spreadsheet (<span id="aantalVerwerkteRijen">0 records</span>, <span id="bestandsgrootte">0 Bytes</span>)</label> <div class="kopieertooltip" id="kopieertooltip"><button id="kopieerbutton" onclick="kopieer()"><span class="kopieertooltiptext">Copy to clipboard</span><i class="far fa-copy"></i></button></div>


<div id="scrollArea" class="clusterize-scroll">
  <div id="contentArea" class="clusterize-content">
  </div>
</div>

<label for="logs">Logs</label>
<div id="scrollAreaLogs" class="clusterize-scroll">
  <div id="contentAreaLogs" class="clusterize-content">
  </div>
</div>
 
</body>
            
          
!
            
              #loader {
      visibility: hidden;
    }

    #queryBlock {
      display: none;
      visibility: hidden;
    }

    #urlInput {
      width: 100%;
    }

    #bestandsgrootte::after, #aantalVerwerkteRijen::after {
      content: none;
    }
    #showquerybutton {
      float: right;
    }

    #sparqlimg {
      height: 25px;
    }

    .startbutton {
      float: left;
    }

    .kopieertooltip, .showquerytooltip, #startbutton {
      position: relative;
      display: inline-block;
    }

    .kopieertooltip {
        visibility: hidden;
        float: right;
        margin-left: 10px;
        margin-bottom: 10px;
    }

    .kopieertooltiptext {
      top: -5px;
      right: 105%;
    }

    .showquerytooltip {
      vertical-align: middle;
    }

    .showquerytooltiptext {
      top: -5px;
      left: 105%; 
    }

    .kopieertooltiptext, .showquerytooltiptext {
      visibility: hidden;
      width: 150px;
      background-color: black;
      color: #fff;
      text-align: center;
      border-radius: 6px;
      padding: 5px 0;
      
      /* Position the tooltip */
      position: absolute;
      z-index: 1;
    }

    .kopieertooltip:hover .kopieertooltiptext, .showquerytooltiptext:hover .showquerytooltiptext {
      visibility: visible;
    }

    .showquerytooltip:hover .showquerytooltiptext {
      visibility: visible;
    }

    #scrollArea {
      height: 23.5em;
      font-size: 10pt;
      margin: .5em 0 1em;
      position: relative;
      overflow: scroll; 
      width: 100%;
    }

    #scrollAreaLogs {
      color: #666;
      height: 6.3em;
      font-size: 9pt;
      line-height: 1.6;
      margin: .5em -999999px 1em 0;
      position: relative;
      overflow: scroll; 
      width: 100%;
    }
    
            
          
!
            
              	let aantalVerwerkteRijen = 0;
let bestandsgrootte = 0;
let data = '';

let clusterize = new Clusterize({
    scrollId: 'scrollArea',
    contentId: 'contentArea'
  });

let clusterizeLogs = new Clusterize({
    scrollId: 'scrollAreaLogs',
    contentId: 'contentAreaLogs'
  });

function kopieer() {
  navigator.clipboard.writeText(data)
    .then(() => {
      console.log('Text copied.');
    })
    .catch(() => {
      console.log('Failed to copy text.');
    });
}

function updateView(res) {
  if (!data) {
        Object.keys(res).forEach((key) => {
          data += key.replace('?', '') + ',';
        });
        data = data.substring(0, data.length - 1); // remove trailing comma
        clusterize.append(['<div>' + data + '</div>']);
        data += '\n';
      } 
        aantalVerwerkteRijen++;
        document.getElementById("aantalVerwerkteRijen").innerHTML = aantalVerwerkteRijen;
        if (aantalVerwerkteRijen === 1) document.getElementById("aantalVerwerkteRijen").innerHTML += " record";
        else document.getElementById("aantalVerwerkteRijen").innerHTML += " records";
        let row = '';
        Object.keys(res).forEach((key) => {
          row += res[key].value + ',';
        });
        row = row.substring(0, row.length - 1); // remove trailing comma
        data += row + '\n';
        clusterize.append(['<div>' + row + '</div>']);

        bestandsgrootte += byteCount(row);
        document.getElementById("bestandsgrootte").innerHTML = formatBytes(bestandsgrootte, 2);
}
  
function byteCount(s) {
    return encodeURI(s).split(/%..|./).length - 1;
}

function fetchRecords() {
  const url = document.getElementById('urlInput').value;
  
  data = '';
  aantalVerwerkteRijen = 0;
  bestandsgrootte = 0;
 // document.getElementById("result").innerHTML = ''';

  //check if url is filled
  if (url.length != 0) {    
    document.getElementById("loader").style.visibility = 'visible';
    const query = document.getElementById("query").value;

    window.logger.log = function (level, message, data) {
      // Only keep Requesting logs
      if (message.indexOf('Requesting') != -1) {
        let log = message + '\n';
        // Add to UI
        clusterizeLogs.append(['<div>' + log + '</div>']);
      }
    };
    const myEngine = Comunica.newEngine();
    myEngine.query(query,
  { sources: [ { type: 'hypermedia', value: url } ], log: window.logger })
  .then(function (result) {
    result.bindingsStream.on('data', function (data) {
      const res = data.toObject();
      updateView(res);
      });
    result.bindingsStream.on('end', function () {
      document.getElementById("loader").style.visibility = 'hidden';
      if (!data.length) {
                clusterize.append(['<div>' + "Geen data gevonden." + '</div>']);
      }
    });
    });

    document.getElementById("kopieertooltip").style = 'visibility: visible';

  } else {
    console.log("no url provided");
  }
}

function formatBytes(a,b){if(0==a)return"0 Bytes";var c=1024,d=b||2,e=["Bytes","KB","MB","GB","TB","PB","EB","ZB","YB"],f=Math.floor(Math.log(a)/Math.log(c));return parseFloat((a/Math.pow(c,f)).toFixed(d))+" "+e[f]}
  
function showquery() {
  if (document.getElementById('queryBlock').style.display === '') {
    document.getElementById('queryBlock').style.display = 'inline';
    new YASQE.fromTextArea(document.getElementById('query'))
    document.getElementById('queryBlock').style.visibility = 'visible';
  }
  else if (document.getElementById('queryBlock').style.display === 'none') {
    document.getElementById('queryBlock').style.display = 'inline';
    document.getElementById('queryBlock').style.visibility = 'visible';
  } else {
    document.getElementById('queryBlock').style.display = 'none';
    document.getElementById('queryBlock').style.visibility = 'hidden';
  }
}
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.

Console