(function (Scratch) { 'use strict'; // I LOVE DOGS const dogFacts = [ "Dogs' sense of smell is at least 40x better than ours.", "Some dogs are incredible swimmers, like Newfoundlands.", "A dog's nose print is unique, much like a human's fingerprint.", "The Basenji is the only breed of dog that doesn't bark, but it can yodel.", "Greyhounds can reach speeds of up to 45 miles per hour.", "Dogs have three eyelids, including one to keep their eyes moist and protected.", "All puppies are born deaf.", "A dog’s sense of hearing is more than 10 times more acute than a human’s.", "Dogs have about 1,700 taste buds, while humans have about 9,000.", "A dog's whiskers are used to 'feel' the world around them.", "The average dog is as intelligent as a two-year-old human child.", "Dalmatians are born completely white and develop their spots as they age.", "Dogs can breathe in and out at the same time.", "A group of puppies is called a litter, while a group of adult dogs is a pack.", "Dogs curl up in a ball when they sleep to protect their vital organs.", "The Bloodhound’s sense of smell is so spot on that it can be admitted as evidence in a court of law.", "The Poodle’s haircut was originally meant to improve its swimming abilities.", "Three dogs survived the sinking of the Titanic.", "A dog’s nose is often wet to help it absorb scent chemicals.", "The tallest dog in the world was a Great Dane named Zeus, standing 44 inches tall.", "Dogs have about 18 muscles to move each ear.", "Chihuahuas are named after the state in Mexico where they were discovered.", "Dogs don't sweat like humans; they sweat through the pads of their paws.", "A dog’s heart beats much faster than a human heart.", "The most popular dog breed in the U.S. for decades was the Labrador Retriever.", "Dogs can learn over 100 words and gestures.", "Puppies have 28 teeth, while adult dogs have 42.", "Ancient Egyptians frequently mummified their beloved dogs.", "Dogs have a special membrane in their eye called the tapetum lucidum, which allows them to see in the dark.", "Service dogs are trained to know when their owner is about to have a seizure.", "A dog’s wagging tail doesn’t always mean they are happy; it can mean they are agitated." ]; let dogBreeds = [ 'Beagle', 'Boxer', 'Bulldog', 'Chihuahua', 'Dachshund', 'Dalmatian', 'Doberman', 'German Shepherd', 'Golden Retriever', 'Great Dane', 'Greyhound', 'Huskies', 'Labrador Retriever', 'Maltese', 'Mastiff', 'Newfoundland', 'Pomeranian', 'Poodle', 'Pug', 'Rottweiler', 'Saint Bernard', 'Samoyed', 'Shih Tzu', 'Shiba Inu', 'Siberian Husky', 'Staffordshire Bull Terrier', 'Vizsla', 'Weimaraner', 'Whippet', 'Yorkshire Terrier' ]; class DOG { getInfo() { return { id: 'ginxilovedogs', name: 'DOGS', color1: '#A0522D', // Sienna Brown color2: '#8B4513', // Saddle Brown color3: '#5D2E0C', blocks: [ { opcode: 'randomdogfact', blockType: Scratch.BlockType.REPORTER, text: 'random dog fact from [FORMAT]', disableMonitor: true, arguments: { FORMAT: { type: Scratch.ArgumentType.STRING, menu: 'FORMAT_MENU' } } }, { opcode: 'dogscool', blockType: Scratch.BlockType.BOOLEAN, text: 'are dogs cool?', disableMonitor: true, }, { opcode: 'doginfo', blockType: Scratch.BlockType.REPORTER, text: 'get info of breed [BREED]', disableMonitor: true, arguments: { BREED: { type: Scratch.ArgumentType.STRING, menu: 'BREED_MENU' } } } ], menus: { FORMAT_MENU: { acceptReporters: true, items: ['source 1 (dogapi.dog)', 'source 2 (dog-api.kinduff)', 'source 3 (local. faster!)'] }, BREED_MENU: { acceptReporters: true, items: dogBreeds } } }; } randomdogfact(args) { if (args.FORMAT == "source 1 (dogapi.dog)") { return fetch("https://dogapi.dog/api/v2/facts") .then((response) => response.json()) .then((data) => String(data.data[0].attributes.body)) .catch(() => 'Bark! Something went wrong.'); } else if (args.FORMAT == "source 2 (dog-api.kinduff)") { return fetch("https://dog-api.kinduff.com/api/facts") .then((response) => response.json()) .then((data) => String(data.facts[0])) .catch(() => 'Bark! Something went wrong.'); } else { return dogFacts[Math.floor(Math.random() * dogFacts.length)]; } } dogscool() { return true; } doginfo(args) { if (!dogBreeds.includes(args.BREED)) { return "Breed not found in list."; } let breed = args.BREED; // Add "dog" to search query for clarity on Wikipedia let searchQuery = breed + " dog"; return fetch("https://en.wikipedia.org/w/api.php?action=query&prop=extracts&exlimit=1&titles=" + encodeURIComponent(searchQuery) + "&explaintext=1&exsectionformat=plain&format=json&origin=*") .then((response) => response.json()) .then((data) => { const pageId = Object.keys(data.query.pages)[0]; if (pageId === "-1") return "Could not find info for this breed."; let extract = data.query.pages[pageId].extract; extract = extract.replace(/\s{2,}/g, ' '); return extract.split('.').slice(0, 2).join('.') + '. (Source: Wikipedia)'; }) .catch(() => 'Bark! Something went wrong.'); } } Scratch.extensions.register(new DOG()); })(Scratch);