我有一个扩展名(在许多其他功能中),将gif放在登录表单上。该扩展用于使我们在工作中经常使用的站点更加用户友好。 (删除大量无用的元素,简化一些,添加一些)。现在,我要完成的事情是从www.9gag.com/gif添加顶级GIF。 (不用担心,这是扩展程序设置中的可选附加功能。)
现在,我如何使扩展名在后台加载www.9gag.com/gif(或对用户隐藏),并从9gag返回顶部gif的网址?
var videoNr = Math.floor((Math.random() * GIFs.length) + 0);
var kilde = document.createElement("div");
kilde.href = "";
kilde.alt = "GIF!";
var video = document.createElement("video");
video.src = GIFs[videoNr]; //Gets random gif from array
video.controls = true;
video.autoplay = true;
video.muted = true;
video.id = "videoen";
video.style.width = "478px";
video.style.position = "absolute";
video.style.left = "50%";
video.style.transform = "translate(-50%)";
video.type = "video/mp4";
video.preload = "auto";
video.loop = "loop";
kilde.appendChild(video);
document.getElementById("feide:login").children[0].appendChild(kilde);
video.addEventListener("click", function() { video.play(); });
如您所见,我使用mp4格式,这是因为9gag gifs arent确实是gifs。无论如何,正如您在video.src下看到的那样,我目前仅从必须手动添加链接的数组中获取链接。如果可以更改,那么video.src始终是9gag的顶级视频/ gif,那就太好了。但是如何?
答案 0 :(得分:0)
您可以向9gag发出GET Request并获取新帖子列表。
检查https://9gag.com/v1/featured-posts此地址以获得下一个处理的响应
{"meta":{"timestamp":1548522927,"status":"Success","sid":":0DWBRXTUNWeMRVRywEVJVDTUFVY"},"data":{"items":[{"itemId":"26324","title":"[Graphic] PETA BBQ Prop Dog On The Street To Promote Veganism","url":"https:\/\/9gag.com\/gag\/aB0nGz2","imageURL":"https:\/\/miscmedia-9gag-fun.9cache.com\/images\/featured\/1548396244.3219_EmePYr_300.jpg","upVoteCount":313,"commentsCount":503},{"itemId":"26325","title":"Man Says Emotional Support Alligator Helps His Depression","url":"https:\/\/9gag.com\/gag\/av8ARDM","imageURL":"https:\/\/miscmedia-9gag-fun.9cache.com\/images\/featured\/1548402572.621_Ypa8EG_300.jpg","upVoteCount":278,"commentsCount":57},{"itemId":"26323","title":"Resident Evil Netflix TV Series Reportedly in the Works","url":"https:\/\/9gag.com\/gag\/aXYrW7V","imageURL":"https:\/\/miscmedia-9gag-fun.9cache.com\/images\/featured\/1548392462.5186_e9A7UT_300.jpg","upVoteCount":66,"commentsCount":75},{"itemId":"26322","title":"A 'Baby Shark' TV Show Is Reportedly Coming To Netflix","url":"https:\/\/9gag.com\/gag\/aB0nGVD","imageURL":"https:\/\/miscmedia-9gag-fun.9cache.com\/images\/featured\/1548391042.4857_epeVaN_300.jpg","upVoteCount":11,"commentsCount":20},{"itemId":"26315","title":"Angry Mum Throws Flip-Flop And Hits Daughter From Incredible Distance","url":"https:\/\/9gag.com\/gag\/a2Z18dp","imageURL":"https:\/\/miscmedia-9gag-fun.9cache.com\/images\/featured\/1548381083.5393_TujA5y_300.jpg","upVoteCount":1365,"commentsCount":203},{"itemId":"26316","title":"Family Finds A 2m-Long Goanna Eating Their Cats' Food In The Kitchen","url":"https:\/\/9gag.com\/gag\/a6O1X9e","imageURL":"https:\/\/miscmedia-9gag-fun.9cache.com\/images\/featured\/1548381189.2347_nY3unU_300.jpg","upVoteCount":205,"commentsCount":54},{"itemId":"26317","title":"Mom Asks Woman To Donate Breast Milk To Her Son, And She Wants \"It All\"","url":"https:\/\/9gag.com\/gag\/aQRXgGz","imageURL":"https:\/\/miscmedia-9gag-fun.9cache.com\/images\/featured\/1548381193.6082_mYguty_300.jpg","upVoteCount":178,"commentsCount":81},{"itemId":"26318","title":"'The Punisher' Showrunner Wants To Bring Daredevil And Kingpin To Season 3","url":"https:\/\/9gag.com\/gag\/adLgvW9","imageURL":"https:\/\/miscmedia-9gag-fun.9cache.com\/images\/featured\/1548381197.7739_TyvYVu_300.jpg","upVoteCount":58,"commentsCount":54},{"itemId":"26319","title":"Smelling Food For 2 Minutes Will End Your Fatty Food Cravings, Researchers Find","url":"https:\/\/9gag.com\/gag\/aerg1pQ","imageURL":"https:\/\/miscmedia-9gag-fun.9cache.com\/images\/featured\/1548381203.0379_3e5EJU_300.jpg","upVoteCount":60,"commentsCount":65},{"itemId":"26320","title":"This Infinity Puzzle Has No Beginning And No End","url":"https:\/\/9gag.com\/gag\/aXYrLBz","imageURL":"https:\/\/miscmedia-9gag-fun.9cache.com\/images\/featured\/1548381239.6967_RY4AVu_300.jpg","upVoteCount":275,"commentsCount":28},{"itemId":"26321","title":"You Can Now Get A Beard Bouquet For Valentine\u2019s Day","url":"https:\/\/9gag.com\/gag\/a9K1zwZ","imageURL":"https:\/\/miscmedia-9gag-fun.9cache.com\/images\/featured\/1548381248.6908_UneDUV_300.jpg","upVoteCount":17,"commentsCount":29},{"itemId":"26314","title":"Young Man Struggling To Pay For Date In Fancy Restaurant, Waiter Saves The Date","url":"https:\/\/9gag.com\/gag\/amBg19o","imageURL":"https:\/\/miscmedia-9gag-fun.9cache.com\/images\/featured\/1548324427.995_ba8Y8E_300.jpg","upVoteCount":1899,"commentsCount":160},{"itemId":"26312","title":"Fudge Covered Oreo Is Here To Satisfy Your Chocolate Craving","url":"https:\/\/9gag.com\/gag\/aVYxg52","imageURL":"https:\/\/miscmedia-9gag-fun.9cache.com\/images\/featured\/1548305126.7304_aHutUQ_300.jpg","upVoteCount":37,"commentsCount":38},{"itemId":"26313","title":"Farming Simulator Is Getting Its Own Esports League","url":"https:\/\/9gag.com\/gag\/a831A9V","imageURL":"https:\/\/miscmedia-9gag-fun.9cache.com\/images\/featured\/1548311943.165_tuJuRU_300.jpg","upVoteCount":346,"commentsCount":86},{"itemId":"26307","title":"Man Wins $1 On A Scratch Off Ticket, Gets Millionaire Treatment","url":"https:\/\/9gag.com\/gag\/aPYZg4n","imageURL":"https:\/\/miscmedia-9gag-fun.9cache.com\/images\/featured\/1548293945.1561_JY6EDA_300.jpg","upVoteCount":158,"commentsCount":42},{"itemId":"26308","title":"The Stupid Parents In Netflix's Docu \"Abducted in Plain Sight\" Leave People Dumbfounded","url":"https:\/\/9gag.com\/gag\/a9K1Eb1","imageURL":"https:\/\/miscmedia-9gag-fun.9cache.com\/images\/featured\/1548293960.8412_AmYXUJ_300.jpg","upVoteCount":110,"commentsCount":23},{"itemId":"26309","title":"Dog Wakes Up After Being Euthanized, Earns Second Chance At Life","url":"https:\/\/9gag.com\/gag\/aA3GeRp","imageURL":"https:\/\/miscmedia-9gag-fun.9cache.com\/images\/featured\/1548293979.6636_9YPava_300.jpg","upVoteCount":185,"commentsCount":148},{"itemId":"26310","title":"Netflix Now Lets iOS Users Share Movies And Shows To Instagram Stories Directly","url":"https:\/\/9gag.com\/gag\/aMZ4YgM","imageURL":"https:\/\/miscmedia-9gag-fun.9cache.com\/images\/featured\/1548293987.7175_naJunu_300.jpg","upVoteCount":12,"commentsCount":21},{"itemId":"26311","title":"Netflix's Marie Kondo's Promo Glitch Sparks Violent Memes","url":"https:\/\/9gag.com\/gag\/av8Ao3X","imageURL":"https:\/\/miscmedia-9gag-fun.9cache.com\/images\/featured\/1548294001.5974_WyNaXe_300.jpg","upVoteCount":173,"commentsCount":47},{"itemId":"26306","title":"Japan's 7-Eleven Stop Selling Porno Magazines In Run Up To Olympics","url":"https:\/\/9gag.com\/gag\/agng596","imageURL":"https:\/\/miscmedia-9gag-fun.9cache.com\/images\/featured\/1548237157.692_5Y9ymA_300.jpg","upVoteCount":180,"commentsCount":112},{"itemId":"26305","title":"Parts Of Niagara Falls Have Frozen, Leaving Majestic Views","url":"https:\/\/9gag.com\/gag\/aB0nm91","imageURL":"https:\/\/miscmedia-9gag-fun.9cache.com\/images\/featured\/1548237145.9648_ZyNaNA_300.jpg","upVoteCount":258,"commentsCount":41},{"itemId":"26304","title":"Lost Dog Returns Home With New Dog And Goat Friend","url":"https:\/\/9gag.com\/gag\/amBgvzX","imageURL":"https:\/\/miscmedia-9gag-fun.9cache.com\/images\/featured\/1548237135.2801_vAbumE_300.jpg","upVoteCount":949,"commentsCount":90},{"itemId":"26303","title":"'Deadpool 3' Will Go In A \"Completely Different Direction\", Says Ryan Reynolds","url":"https:\/\/9gag.com\/gag\/aqKGgVL","imageURL":"https:\/\/miscmedia-9gag-fun.9cache.com\/images\/featured\/1548225693.441_bAnuVU_300.jpg","upVoteCount":192,"commentsCount":84},{"itemId":"26302","title":"Lawmaker Proposes Porn Tax To Fund Trump's Wall","url":"https:\/\/9gag.com\/gag\/agng5zr","imageURL":"https:\/\/miscmedia-9gag-fun.9cache.com\/images\/featured\/1548225664.8913_uVeLEg_300.jpg","upVoteCount":58,"commentsCount":125},{"itemId":"26299","title":"Addict Calls Cops On Drug Dealer Who Sold Him Sugar Instead Of Crystal Meth","url":"https:\/\/9gag.com\/gag\/aYYrKL2","imageURL":"https:\/\/miscmedia-9gag-fun.9cache.com\/images\/featured\/1548207506.9978_AherYQ_300.jpg","upVoteCount":134,"commentsCount":61},{"itemId":"26300","title":"Unpaid Contractor Wrecks Newly-Built Hotel With Excavator","url":"https:\/\/9gag.com\/gag\/aB0nwqZ","imageURL":"https:\/\/miscmedia-9gag-fun.9cache.com\/images\/featured\/1548207566.7578_Yvezu5_300.jpg","upVoteCount":123,"commentsCount":58},{"itemId":"26301","title":"Hotel Fires Half Its Robot Staff For Failing To Perform Simple Tasks.","url":"https:\/\/9gag.com\/gag\/amBgrz9","imageURL":"https:\/\/miscmedia-9gag-fun.9cache.com\/images\/featured\/1548207590.2274_A9ujeN_300.jpg","upVoteCount":214,"commentsCount":68},{"itemId":"26296","title":"Meet Imma, The Gorgeous Japanese Fashion Model That Doesn't Exist","url":"https:\/\/9gag.com\/gag\/a9K1WW1","imageURL":"https:\/\/miscmedia-9gag-fun.9cache.com\/images\/featured\/1548154708.7888_Y4aXYP_300.jpg","upVoteCount":1519,"commentsCount":240},{"itemId":"26295","title":"Dad Documents His Son Sneaking A Girl Out Of The House Under Mom's Watch","url":"https:\/\/9gag.com\/gag\/aA3GPoo","imageURL":"https:\/\/miscmedia-9gag-fun.9cache.com\/images\/featured\/1548143921.0902_tAReVU_300.jpg","upVoteCount":2655,"commentsCount":147},{"itemId":"26297","title":"This Guy Continues Photoshopping Himself Into Kendall Jenner\u2019s Photos And Makes Them Better","url":"https:\/\/9gag.com\/gag\/a3Q173Q","imageURL":"https:\/\/miscmedia-9gag-fun.9cache.com\/images\/featured\/1548154722.7022_asaQy7_300.jpg","upVoteCount":9922,"commentsCount":333},{"itemId":"26298","title":"Australia's Weather Map Turns Black Due To Record-Breaking Heatwave","url":"https:\/\/9gag.com\/gag\/a0QZd9L","imageURL":"https:\/\/miscmedia-9gag-fun.9cache.com\/images\/featured\/1548154731.5035_TybAsa_300.jpg","upVoteCount":342,"commentsCount":241},{"itemId":"26293","title":"200kg Man Threatens To Sh*t Himself If Flight Attendants Don't Wipe His Ass","url":"https:\/\/9gag.com\/gag\/abYgZNX","imageURL":"https:\/\/miscmedia-9gag-fun.9cache.com\/images\/featured\/1548133768.9271_eBeneM_300.jpg","upVoteCount":1345,"commentsCount":508},{"itemId":"26294","title":"Thief Who Looks Like Ross From Friends Actually Looks Nothing Like Ross","url":"https:\/\/9gag.com\/gag\/abYgZwL","imageURL":"https:\/\/miscmedia-9gag-fun.9cache.com\/images\/featured\/1548133775.765_5yVyZE_300.jpg","upVoteCount":280,"commentsCount":67},{"itemId":"26292","title":"KFC Launches Gravy Scented Candles, That's Your Valentine Gift Sorted","url":"https:\/\/9gag.com\/gag\/az9eEDb","imageURL":"https:\/\/miscmedia-9gag-fun.9cache.com\/images\/featured\/1548122469.4899_DADYQy_300.jpg","upVoteCount":39,"commentsCount":22},{"itemId":"26287","title":"WHO Lists Anti Vaxxers As One Of The Biggest Threats To Public Health","url":"https:\/\/9gag.com\/gag\/an9gq8B","imageURL":"https:\/\/miscmedia-9gag-fun.9cache.com\/images\/featured\/1548122422.8239_AdYLyV_300.jpg","upVoteCount":354,"commentsCount":292},{"itemId":"26288","title":"A Major Reason Millennials Are Buying Homes Is For Their Dogs, Study Reveals","url":"https:\/\/9gag.com\/gag\/aNYPer4","imageURL":"https:\/\/miscmedia-9gag-fun.9cache.com\/images\/featured\/1548122441.673_XYbAGE_300.jpg","upVoteCount":40,"commentsCount":51},{"itemId":"26289","title":"Canada And Norway Are Fighting Over The World's Tallest Moose Statue","url":"https:\/\/9gag.com\/gag\/arGnv7X","imageURL":"https:\/\/miscmedia-9gag-fun.9cache.com\/images\/featured\/1548122445.5191_ZEHu3y_300.jpg","upVoteCount":239,"commentsCount":123},{"itemId":"26290","title":"Massive Sky Corridor Connected Atop 4 Skyscrapers in Chongqing","url":"https:\/\/9gag.com\/gag\/a9K1dAj","imageURL":"https:\/\/miscmedia-9gag-fun.9cache.com\/images\/featured\/1548122454.2242_AXybeJ_300.jpg","upVoteCount":330,"commentsCount":122},{"itemId":"26291","title":"Scientists Have Found A Way To Turn Breast Cancer Cells Into Fat In Mice","url":"https:\/\/9gag.com\/gag\/aQRXqge","imageURL":"https:\/\/miscmedia-9gag-fun.9cache.com\/images\/featured\/1548122460.5291_uMa8AD_300.jpg","upVoteCount":151,"commentsCount":95},{"itemId":"26284","title":"Woman Has Been Expertly Running In The Shape Of Dicks For Years","url":"https:\/\/9gag.com\/gag\/a7315Zz","imageURL":"https:\/\/miscmedia-9gag-fun.9cache.com\/images\/featured\/1548068842.192_abugER_300.jpg","upVoteCount":523,"commentsCount":127},{"itemId":"26285","title":"Photographer Tossed Colorful Powder On Dogs, And The Results Are Magical","url":"https:\/\/9gag.com\/gag\/aoegz9n","imageURL":"https:\/\/miscmedia-9gag-fun.9cache.com\/images\/featured\/1548068848.4736_uSAMeh_300.jpg","upVoteCount":6624,"commentsCount":183},{"itemId":"26286","title":"All Kiwis Are Rallying To Deport A Unbelievably Sh*tty Brit Family","url":"https:\/\/9gag.com\/gag\/a6O1wmq","imageURL":"https:\/\/miscmedia-9gag-fun.9cache.com\/images\/featured\/1548068857.6677_7Aqu4Y_300.jpg","upVoteCount":867,"commentsCount":567},{"itemId":"26283","title":"Super Mario Kart Is Heading To Mobile This Year","url":"https:\/\/9gag.com\/gag\/aXYr0zb","imageURL":"https:\/\/miscmedia-9gag-fun.9cache.com\/images\/featured\/1548052280.9148_eBe6Ah_300.jpg","upVoteCount":102,"commentsCount":84},{"itemId":"26267","title":"Don't Shove Parsley In Your Vagina To Induce Menstruation, Doctor Warns","url":"https:\/\/9gag.com\/gag\/aQRoj0e","imageURL":"https:\/\/miscmedia-9gag-fun.9cache.com\/images\/featured\/1548035014.7026_ESe8un_300.jpg","upVoteCount":66,"commentsCount":97},{"itemId":"26268","title":"Nike To Launch New Air Max Trainers Made Of Fake Grass","url":"https:\/\/9gag.com\/gag\/aD1dNqx","imageURL":"https:\/\/miscmedia-9gag-fun.9cache.com\/images\/featured\/1548035023.7669_3umaNy_300.jpg","upVoteCount":77,"commentsCount":47},{"itemId":"26269","title":"Zoo Creates World's First Reptile Swim-Gym To Fight Snake Obesssity","url":"https:\/\/9gag.com\/gag\/aWYjVL3","imageURL":"https:\/\/miscmedia-9gag-fun.9cache.com\/images\/featured\/1548035041.0813_rANyNa_300.jpg","upVoteCount":113,"commentsCount":49},{"itemId":"26270","title":"Paralyzed Veteran Caught Walking After Given Free House","url":"https:\/\/9gag.com\/gag\/a4QE0nm","imageURL":"https:\/\/miscmedia-9gag-fun.9cache.com\/images\/featured\/1548035048.7018_ArULam_300.jpg","upVoteCount":132,"commentsCount":127},{"itemId":"26271","title":"Boo, World's Cutest Pup, Passed Away Aged 12","url":"https:\/\/9gag.com\/gag\/aA3b7EL","imageURL":"https:\/\/miscmedia-9gag-fun.9cache.com\/images\/featured\/1548035055.3117_tEse9e_300.jpg","upVoteCount":499,"commentsCount":139},{"itemId":"26272","title":"Japanese Netizens Don't Understand Why Everybody Is Choking Sasuke","url":"https:\/\/9gag.com\/gag\/aQRoNVe","imageURL":"https:\/\/miscmedia-9gag-fun.9cache.com\/images\/featured\/1548035081.5139_MeZe4a_300.jpg","upVoteCount":716,"commentsCount":226},{"itemId":"26273","title":"This Phone Case-Spoon-Fork Combo Is Perfect For Scroll-Dining","url":"https:\/\/9gag.com\/gag\/aYYome7","imageURL":"https:\/\/miscmedia-9gag-fun.9cache.com\/images\/featured\/1548035089.8751_7y2YMu_300.jpg","upVoteCount":41,"commentsCount":91},{"itemId":"26274","title":"World's Loneliest Frog Romeo Finally Found His Juliet After 10 Years","url":"https:\/\/9gag.com\/gag\/aXYoR12","imageURL":"https:\/\/miscmedia-9gag-fun.9cache.com\/images\/featured\/1548035095.6675_nuge2e_300.jpg","upVoteCount":483,"commentsCount":83},{"itemId":"26275","title":"Pornhub Reports Traffic Increase During US Government Shutdown","url":"https:\/\/9gag.com\/gag\/aerA7mm","imageURL":"https:\/\/miscmedia-9gag-fun.9cache.com\/images\/featured\/1548035101.2053_HugyRy_300.jpg","upVoteCount":7{
"meta": {
"timestamp": 1548523227,
"status": "Success",
"sid": ":0DWBRXTUNWeMRVRywEVJVDTUFVY"
},
"data": {
"items": [
{
"itemId": "26324",
"title": "[Graphic] PETA BBQ Prop Dog On The Street To Promote Veganism",
"url": "https://9gag.com/gag/aB0nGz2",
"imageURL": "https://miscmedia-9gag-fun.9cache.com/images/featured/1548396244.3219_EmePYr_300.jpg",
"upVoteCount": 313,
"commentsCount": 503
},
{
"itemId": "26325",
"title": "Man Says Emotional Support Alligator Helps His Depression",
"url": "https://9gag.com/gag/av8ARDM",
"imageURL": "https://miscmedia-9gag-fun.9cache.com/images/featured/1548402572.621_Ypa8EG_300.jpg",
"upVoteCount": 279,
"commentsCount": 57
},
...
]
}
}