Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1">
- </head>
- <!--
- factotron 3000, version 1.0
- Feel free to distribute.
- The code in here is not minified/uglified/mangled or whatever.
- This code is under MIT license (see below)
- -->
- <!--
- Copyright 2017, James Russell
- Permission is hereby granted, free of charge, to any person
- obtaining a copy of this software and associated documentation
- files (the "Software"), to deal in the Software without
- restriction, including without limitation the rights to use,
- copy, modify, merge, publish, distribute, sublicense, and/or
- sell copies of the Software, and to permit persons to whom the
- Software is furnished to do so, subject to the following conditions:
- The above copyright notice and this permission notice shall be
- included in all copies or substantial portions of the Software.
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
- OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
- HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
- WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- OTHER DEALINGS IN THE SOFTWARE.
- -->
- <title>factotron 3000</title>
- <style>
- body {
- font-family: sans-serif;
- line-height: 1.8em;
- }
- #facts-questionnaire {
- max-width: 40em;
- padding: 1em;
- }
- .opt-label {
- min-width: 10em;
- display: inline-block;
- }
- .text-input {
- width: 20em;
- }
- #generated-code {
- width: 30em;
- }
- </style>
- <body>
- <div id="facts-questionnaire">
- <h3>factotron 3000</h3>
- version 1.0, by James Russell
- <br>
- Google Fact Check API Generator
- <hr>
- <span class="opt-label">Fact-Checker Author</span>
- <input class="text-input" type="text" key="author.name" placeholder="Debunkers, Inc."></input>
- <br>
- <span class="opt-label">Fact-Checker URL</span>
- <input class="text-input" type="text" key="url" placeholder="http://example.com/news/dihydrogen-monoxide"></input>
- <br>
- <span class="opt-label">Date of Fact-Check</span>
- <input class="date-input" type="date" key="datePublished" placeholder="YYYY-MM-DD"></input>
- <br>
- <hr>
- <span class="opt-label">Claim Author</span>
- <input class="text-input" type="text" key="itemReviewed.author.name" placeholder="Conspiracyland"></input>
- <br>
- <span class="opt-label">Claim Author is</span>
- <input type="radio" class="author-radio-button" name="opt-fact-claim-authortype" value="Organization">
- <span class="radio-label">Organization</span>
- <input type="radio" class="author-radio-button" name="opt-fact-claim-authortype" value="Person">
- <span class="radio-label">Person</span>
- <br>
- <span class="opt-label">Claim Made</span>
- <input class="text-input" type="text" key="claimReviewed" placeholder="DHMO (Water) can exist as a gas"></input>
- <br>
- <span class="opt-label">Claim URL</span>
- <input class="text-input" type="text" key="itemReviewed.author.sameAs" placeholder="http://example.conspiracyland.org/five-facts-about-DHMO-you-wouldnt-believe"></input>
- <br>
- <span class="opt-label">Date of Claim</span>
- <input class="date-input" type="date" key="itemReviewed.datePublished" placeholder="YYYY-MM-DD"></input>
- <br>
- <hr>
- <span class="opt-label">Claim Truth Rating</span><br>
- <input type="radio" class="claim-radio-button" name="opt-fact-claim-rating" value="5">
- <span class="radio-label">True</span>
- <input type="radio" class="claim-radio-button" name="opt-fact-claim-rating" value="4">
- <span class="radio-label">Mostly True</span>
- <input type="radio" class="claim-radio-button" name="opt-fact-claim-rating" value="3">
- <span class="radio-label">Half True</span>
- <input type="radio" class="claim-radio-button" name="opt-fact-claim-rating" value="2">
- <span class="radio-label">Mostly False</span>
- <input type="radio" class="claim-radio-button" name="opt-fact-claim-rating" value="1">
- <span class="radio-label">False</span>
- <input type="radio" class="claim-radio-button" name="opt-fact-claim-rating" value="-1" id="other-button">
- <span class="radio-label">Other (explain)</span>
- <br>
- <input class="text-input" type="text" id="verbose-truth" key="reviewRating.alternateName" placeholder="Explain if Other"></input>
- <br>
- <hr>
- <h4>↓ generated code ↓</h4>
- <textarea id="generated-code" spellcheck="false"></textarea>
- </div>
- <br>
- <a href="https://search.google.com/structured-data/testing-tool">Fact Check code can be tested here</a>
- <br>
- <a href="https://developers.google.com/search/docs/data-types/factcheck">Google's Fact Check API can be found here</a>
- </body>
- <script>
- (function () {
- var truth_lookup = {
- 5: 'True',
- 4: 'Mostly True',
- 3: 'Half True',
- 2: 'Mostly False',
- 1: 'False',
- };
- var check_fields = [
- 'datePublished',
- 'url',
- 'itemReviewed.author.@type',
- 'itemReviewed.author.name',
- 'itemReviewed.author.sameAs',
- 'itemReviewed.datePublished',
- 'claimReviewed',
- 'author.name',
- 'reviewRating.ratingValue',
- 'reviewRating.bestRating',
- 'reviewRating.worstRating',
- 'reviewRating.alternateName',
- ];
- // from the Google spec
- var claim_object = {
- "@context": "http://schema.org", // constant
- "@type": "ClaimReview", // constant
- "datePublished": null, // checker date (YYYY-MM-DD)
- "url": null, // checker URL
- "itemReviewed":
- {
- "@type": "CreativeWork",
- "author":
- {
- "@type": null, // Organization or Individual
- "name": null, // Claimant
- "sameAs": null // claim URL
- },
- "datePublished": null // Claim publish date (YYYY-MM-DD)
- },
- "claimReviewed": null, // Claim as reviewed, under 75 characters
- "author":
- {
- "@type": "Organization", // fact checkers are always organizations
- "name": null // Verbose name of checker
- },
- "reviewRating":
- {
- "@type": "Rating", // Kept the same as the Google spec for now
- "ratingValue": null, // 1-5, or -1
- "bestRating": null, // 5 or -1
- "worstRating": null, // 1 or -1
- "alternateName" : null // Verbose name of claim
- }
- };
- // yoinked from MDN as an alternative to eval()
- function setDescendantProp(obj, desc, value) {
- var arr = desc.split('.');
- while (arr.length > 1) {
- obj = obj[arr.shift()];
- }
- obj[arr[0]] = value;
- }
- // also borrowed from MDN
- function getDescendantProp(obj, desc) {
- var arr = desc.split('.');
- while (arr.length) {
- obj = obj[arr.shift()];
- }
- return obj;
- }
- function validate() {
- var valid = true;
- for(var i=0; i < check_fields.length; i++) {
- var v = getDescendantProp(claim_object, check_fields[i]);
- if(!v)
- valid = false;
- else if(v.length = 0)
- valid = false;
- }
- return valid;
- }
- function update() {
- var code = null;
- if(!validate()) {
- code = "Please fill in all fields.";
- } else {
- var jstr = JSON.stringify(claim_object, null, 2);
- code = "\<script type=\"application/ld+json\"\>\n"
- + jstr
- + "\n\</script\>";
- }
- var codetxt = document.querySelector('#generated-code');
- codetxt.value = code;
- }
- function updateTextField(txt) {
- var key = txt.getAttribute("key");
- var val = txt.value;
- setDescendantProp(claim_object, key, val);
- update();
- }
- function updateDateField(date) {
- var key = date.getAttribute("key");
- var val = date.value;
- setDescendantProp(claim_object, key, val);
- update();
- }
- function setRating(val) {
- claim_object.reviewRating.ratingValue = "" + val;
- // Normal claims
- if(val != -1) { // this is intentional
- claim_object.reviewRating.alternateName = truth_lookup[val];
- claim_object.reviewRating.bestRating = "5";
- claim_object.reviewRating.worstRating = "1";
- document.querySelector('#verbose-truth').disabled = true;
- } else {
- // "other" variety claims
- claim_object.reviewRating.bestRating = "-1";
- claim_object.reviewRating.worstRating = "-1";
- document.querySelector('#verbose-truth').disabled = false;
- }
- update();
- }
- onload = function() {
- var radios = document.querySelectorAll('.claim-radio-button');
- for(var i=0; i < radios.length; i++) {
- radios[i].checked = false;
- radios[i].onclick = function(e) {
- setRating(e.target.value);
- }
- }
- radios = document.querySelectorAll('.author-radio-button');
- for(var i=0; i < radios.length; i++) {
- radios[i].checked = false;
- radios[i].onclick = function(e) {
- claim_object.itemReviewed.author["@type"] = e.target.value;
- update();
- }
- }
- var textFields = document.querySelectorAll('.text-input');
- for(var i=0; i < textFields.length; i++) {
- textFields[i].value = "";
- textFields[i].onchange = function(e) {
- updateTextField(e.target);
- }
- }
- var dateFields = document.querySelectorAll('.date-input');
- for(var i=0; i < dateFields.length; i++) {
- dateFields[i].value = "";
- dateFields[i].onchange = function(e) {
- updateDateField(e.target);
- }
- }
- var verboseTruth = document.querySelector('#verbose-truth');
- var otherRadio = document.querySelector('#other-button');
- verboseTruth.onchange = function(e) {
- updateTextField(e.target);
- otherRadio.checked = true;
- setRating(-1);
- }
- update();
- }
- }());
- </script>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement