Best JavaScript code snippet using storybook-root
MenuScene.ts
Source:MenuScene.ts
1import phaser from 'phaser'2// TODO: @types/bootstrap@5.0.0ããªãªã¼ã¹ããããã¯ãã3// @ts-ignore4import { Modal } from 'bootstrap'5import { createSpriteObject } from '../functions/GameObjectManager'6import { outputGameLog, replaceText } from '../functions/Util'7import { LoadScene } from './LoadScene'8import { SpriteData, SpriteLayer, SpriteObject } from '../../../server/interfaces/presenters/types'9import * as api from '../functions/Api'10import { getUserSignUpModal, getEnterAsDefaultUserModal, getLoginModal, getOptionModal } from '../functions/Util'11import { GameState } from '../../../server/interfaces/presenters/GameState'12const modalElement: HTMLElement = document.getElementById('modal') as HTMLElement13let enterTheWorldElement: HTMLElement14export class MenuScene extends phaser.Scene {15 // ã²ã¼ã ç¶æ
16 private gameState: GameState = GameState.instance17 private spriteLayer: SpriteLayer = new Map()18 constructor() {19 super({20 key: 'MENU'21 })22 }23 // TODO åã·ã¼ã³ã¯init()âpreload()âcreate()ã®é çªã«å®è¡ããã¦ããããå®äºãå¾
ã£ã¦å®è¡ãããããã§ã¯ãªãã®ã§24 // é¢æ°ã®ä¸ã«promiseãªãã®ãå
¥ã£ã¦ããã¨çµäºããé çªãåå¾ãã¦ãã¾ããã®ã§ãåæã§å¦çãå®è¡ãããããã«25 // å®äºãã©ã°ãæããããªã©ãã¦å·¥å¤«ããå¿
è¦ãããã調ã¹ãéãã¯ããããæ¹æ³ã¯ç¡ããããã£ã¨è¯ãæ¡ããã°å¤ãããã26 // ä¼¼ããããªæ©ã¿ãæã¤äººï¼ https://phaser.discourse.group/t/scene-event-after-create-has-completed/361527 // (âã®äººã¯load.json()使ãæ¹æ³ã§ç´å¾ãã¦ãããã©ãload.json()ã¯getã¯åºæ¥ããã©ãpostã¯ã§ããªããã ããã)28 init(): void {29 console.log('init')30 const commonGameLog = api.gameLog.COMMON31 outputGameLog(commonGameLog.WELCOME)32 if (api.sesUser.userName != '${initName}') {33 const helloUser: string = replaceText(commonGameLog.HELLO_USER, api.sesUser.userName)34 outputGameLog(helloUser)35 }36 this.preload(true)37 }38 preload(isPreFuncComplete = false): void {39 if (!isPreFuncComplete) return40 console.log('preload')41 this.create(undefined, true)42 }43 async create(data?: object, isPreFuncComplete = false): Promise<void> {44 if (!isPreFuncComplete) return45 console.log('create')46 this.add.image(0, 0, 'TITLE').setOrigin(0)47 // this.add.image(this.game.renderer.width * 0.5, this.game.renderer.height * 0.2, 'LOGO').setDepth(1)48 // const enterButton: phaser.GameObjects.Image = this.add.image(49 // this.game.renderer.width * 0.5,50 // this.game.renderer.height * 0.5,51 // 'PLAY'52 // )53 // const optionsButton: phaser.GameObjects.Image = this.add54 // .image(this.game.renderer.width * 0.5, this.game.renderer.height * 0.5 + 100, 'OPTIONS')55 // .setDepth(1)56 const logo: phaser.GameObjects.Text = this.add.text(57 this.game.renderer.width * 0.5,58 this.game.renderer.height * 0.3,59 'BUDDHA.HELIX',60 {61 fontSize: '80px',62 color: 'white'63 }64 )65 logo.setOrigin(0.5)66 const enterButton: phaser.GameObjects.Text = this.add.text(67 this.game.renderer.width * 0.5,68 this.game.renderer.height * 0.5,69 '<ENTER>',70 {71 fontSize: '35px',72 color: 'white'73 }74 )75 enterButton.setOrigin(0.5)76 let logInOutButton: phaser.GameObjects.Text77 if (api.sesUser.userId === 'default') {78 logInOutButton = this.add.text(79 this.game.renderer.width * 0.5,80 this.game.renderer.height * 0.5 + 80,81 '<LOGIN>',82 {83 fontSize: '35px',84 color: 'white'85 }86 )87 } else {88 logInOutButton = this.add.text(89 this.game.renderer.width * 0.5,90 this.game.renderer.height * 0.5 + 80,91 '<LOGOUT>',92 {93 fontSize: '31px',94 color: 'white'95 }96 )97 }98 logInOutButton.setOrigin(0.5)99 const optionsButton: phaser.GameObjects.Text = this.add.text(100 this.game.renderer.width * 0.5,101 this.game.renderer.height * 0.5 + 160,102 '<OPTIONS>',103 {104 fontSize: '27px',105 color: 'white'106 }107 )108 optionsButton.setOrigin(0.5)109 // æ°è¦ç»é²ç»é¢ã表示110 if (api.sesUser.userName === '${initName}') {111 const userSignUpModalElement = getUserSignUpModal()112 const userSignUpModal = new Modal(userSignUpModalElement, {113 keyboard: false,114 backdrop: 'static'115 })116 userSignUpModal.show()117 const signUpElement = document.getElementById('sign-up') as HTMLElement118 signUpElement.addEventListener('click', async () => {119 const userName: string = (document.getElementById('user-name') as HTMLInputElement).value120 const userLocation: string = (document.getElementById('user-location') as HTMLInputElement).value121 const userLanguage: string = (document.getElementById('user-language') as HTMLInputElement).value122 const updateProp = { userName: userName, location: userLocation, lang: userLanguage }123 const retCode: number = await api.updateSesUser(updateProp)124 if (retCode === 200) location.reload()125 })126 return127 }128 // MENUspriteã¢ãã¡ã¼ã·ã§ã³è¡¨ç¤º129 const menuSpriteData: SpriteData = await api.getSpriteData()130 const menuAnimeCd: string = menuSpriteData[0][0].animeCd131 await createSpriteObject(this, this.spriteLayer)132 const hoverSprite: phaser.GameObjects.Sprite = (this.spriteLayer.get(menuAnimeCd) as SpriteObject).spriteObject133 hoverSprite.anims.setTimeScale(1 / 6) // frameRate=4ãããã©ã«ãã24ãªã®ã§1/6ã«ãã¦ãã134 hoverSprite.setScale(2)135 hoverSprite.setOrigin(0.5)136 hoverSprite.setVisible(false)137 // ä¸çã«å
¥ã138 const enterTheWorld = (): void => {139 this.gameState.scene = 'PLAY'140 this.scene.add('LOAD', LoadScene, false)141 this.scene.start('LOAD').stop('MENU')142 }143 // ã¢ã¼ãã«ã¦ã¤ã³ãã¦ã®è¡¨ç¤ºãçµãã£ããå度åãã¿ã³ãsetInteractiveãã144 modalElement.addEventListener('hidden.bs.modal', () => {145 enterButton.setInteractive()146 logInOutButton.setInteractive()147 optionsButton.setInteractive()148 })149 enterButton.setInteractive()150 enterButton.on('pointerover', () => {151 hoverSprite.setVisible(true)152 hoverSprite.play(menuAnimeCd + '_' + 'walk_back')153 hoverSprite.x = enterButton.x - enterButton.width154 hoverSprite.y = enterButton.y155 })156 enterButton.on('pointerout', () => {157 hoverSprite.setVisible(false)158 })159 enterButton.on('pointerup', () => {160 if (api.sesUser.userId === 'default') {161 enterButton.disableInteractive()162 logInOutButton.disableInteractive()163 optionsButton.disableInteractive()164 const enterAsDefaultUserModalElement = getEnterAsDefaultUserModal()165 const enterAsDefaultUserModal = new Modal(enterAsDefaultUserModalElement, { keyboard: false })166 enterAsDefaultUserModal.show()167 enterTheWorldElement = document.getElementById('enter-the-world') as HTMLElement168 enterTheWorldElement.addEventListener('click', () => {169 modalElement.addEventListener('hidden.bs.modal', enterTheWorld)170 })171 return172 }173 enterTheWorld()174 })175 logInOutButton.setInteractive()176 logInOutButton.on('pointerover', () => {177 hoverSprite.setVisible(true)178 hoverSprite.play(menuAnimeCd + '_' + 'walk_back')179 hoverSprite.x = logInOutButton.x - logInOutButton.width180 hoverSprite.y = logInOutButton.y181 })182 logInOutButton.on('pointerout', () => {183 hoverSprite.setVisible(false)184 })185 logInOutButton.on('pointerup', () => {186 if (api.sesUser.userId === 'default') {187 // ã¢ã¼ãã«ã¦ã¤ã³ãã¦ã表示ããã¦ããã¨ããåãã¿ã³ãåå¿ãã¦ãã¾ãã®ã§disableããã188 enterButton.disableInteractive()189 logInOutButton.disableInteractive()190 optionsButton.disableInteractive()191 const loginModalElement = getLoginModal()192 const loginModal = new Modal(loginModalElement, { keyboard: false })193 loginModal.show()194 return195 }196 location.href = './auth/logout'197 })198 optionsButton.setInteractive()199 optionsButton.on('pointerover', () => {200 hoverSprite.setVisible(true)201 hoverSprite.play(menuAnimeCd + '_' + 'walk_back')202 hoverSprite.x = optionsButton.x - optionsButton.width203 hoverSprite.y = optionsButton.y204 })205 optionsButton.on('pointerout', () => {206 hoverSprite.setVisible(false)207 })208 optionsButton.on('pointerup', () => {209 enterButton.disableInteractive()210 logInOutButton.disableInteractive()211 optionsButton.disableInteractive()212 const optionModalElement = getOptionModal()213 const optionModal = new Modal(optionModalElement, { keyboard: false })214 optionModal.show()215 return216 })217 }...
commons.js
Source:commons.js
1var DOMAIN = "https://channeli.in";2function addClass(element, classToAdd) {3 element.classList.add(classToAdd);4}5function removeClass(element, classToRemove) {6 element.classList.remove(classToRemove);7}8function createTables() {9 loadApps();10 loadGames();11 loadImgTools();12}13function activateTabs() {14 var tabs = document.querySelectorAll(".ui.top.attached.tabular.menu .item");15 var tab;16 for (var i = 0; i < tabs.length; i++) {17 tab = tabs[i];18 tab.addEventListener("click", function () {19 var activeTab = document.querySelector(".ui.top.attached.tabular.menu .active.item");20 var activeContent = document.querySelector(".ui.bottom.attached.active.tab.segment");21 removeClass(activeTab, "active");22 addClass(this, "active");23 removeClass(activeContent, "active");24 var contentToActivate = document.querySelectorAll("[data-tab='" + this.dataset.tab + "']")[1];25 addClass(contentToActivate, "active");26 });27 }28}29function setupAnchors() {30 var anchors = document.getElementsByTagName("a");31 for (var j = 0; j < anchors.length; j++) {32 const anchor = anchors[j];33 anchor.onclick = function () {34 chrome.tabs.create({url: anchor.href})35 };36 }37}38function setupLogInOutButton() {39 var logInOutButton = document.getElementById("log-in-out-button");40 chrome.runtime.getBackgroundPage(function (backgroundPage) {41 if (backgroundPage.userIsLoggedIn) {42 logInOutButton.innerText = "Log out";43 addClass(logInOutButton, "negative");44 logInOutButton.href = DOMAIN + "/logout/";45 } else {46 logInOutButton.innerText = "Log in";47 addClass(logInOutButton, "primary");48 logInOutButton.href = DOMAIN + "/login/";49 }50 setupAnchors();51 });52}53function firstThingsFirst() {54 createTables();55 activateTabs();56 setupLogInOutButton();57}58document.addEventListener("DOMContentLoaded", function () {59 loadItems(firstThingsFirst);...
index.js
Source:index.js
1async function loadArticles(){2 articles = await getArticles()3 console.log(articles)4 const article_list = document.getElementById("articles")5 articles.forEach(article => {6 const newArticle = document.createElement("li");7 newArticle.setAttribute("id", article._id)8 newArticle.innerText = article.title9 newArticle.setAttribute("onclick","articleDetail(this.id)")10 article_list.appendChild(newArticle)11 });12 13}14async function checkLogin(){15 const name = await getName();16 console.log(name)17 const username = document.getElementById("username")18 const loginoutButton = document.getElementById("loginout")19 if(name){20 username.innerText = name.email21 loginoutButton.innerText = "ë¡ê·¸ìì"22 loginoutButton.setAttribute("onclick", "logout()")23 }else{24 username.innerText = "ë¡ê·¸ì¸í´ì£¼ì¸ì"25 loginoutButton.innerText = "ë¡ê·¸ì¸"26 loginoutButton.setAttribute("onclick", "location.href='/login.html'")27 }28}29checkLogin();...
Using AI Code Generation
1import { logInOutButton } from 'storybook-root-decorator';2export default {3};4export const LogInOutButton = () => {5 return html`<log-in-out-button></log-in-out-button>`;6};7export const LogInOutButton2 = () => {8 return html`<log-in-out-button></log-in-out-button>`;9};10export const LogInOutButton3 = () => {11 return html`<log-in-out-button></log-in-out-button>`;12};13export const LogInOutButton4 = () => {14 return html`<log-in-out-button></log-in-out-button>`;15};16export const LogInOutButton5 = () => {17 return html`<log-in-out-button></log-in-out-button>`;18};19export const LogInOutButton6 = () => {20 return html`<log-in-out-button></log-in-out-button>`;21};22export const LogInOutButton7 = () => {23 return html`<log-in-out-button></log-in-out-button>`;24};25export const LogInOutButton8 = () => {26 return html`<log-in-out-button></log-in-out-button>`;27};28export const LogInOutButton9 = () => {29 return html`<log-in-out-button></log-in-out-button>`;30};31export const LogInOutButton10 = () => {32 return html`<log-in-out-button></log-in-out-button>`;33};34export const LogInOutButton11 = () => {
Using AI Code Generation
1import {logInOutButton} from 'storybook-root'2logInOutButton()3logInOutButton('login')4logInOutButton('logout')5logInOutButton('something else')6logInOutButton(123)7logInOutButton(true)8logInOutButton(false)9logInOutButton(null)10logInOutButton(undefined)11logInOutButton({})12logInOutButton([])13logInOutButton(['login'])14logInOutButton(['logout'])15logInOutButton(['something else'])16logInOutButton([123])17logInOutButton([true])18logInOutButton([false])19logInOutButton([null])20logInOutButton([undefined])21logInOutButton([{}])22logInOutButton([[],[]])23logInOutButton([['login'],['logout'],['something else'],[123],[true],[false],[null],[undefined],[{}],[[],[]]])24logInOutButton([['login'],['logout'],['something else'],[123],[true],[false],[null],[undefined],[{}],[[],[]]],'login')
Using AI Code Generation
1import { logInOutButton } from 'storybook-root';2logInOutButton();3export const logInOutButton = () => {4 console.log('Hello world');5};6module.exports = {7 module: {8 {9 path.resolve(__dirname, '../src'),10 path.resolve(__dirname, '../test'),11 },12 },13};
Using AI Code Generation
1import { logInOutButton } from 'storybook-root';2import { logInOutButton } from 'storybook-root';3import { logInOutButton } from 'storybook-root';4import { logInOutButton } from 'storybook-root';5import { logInOutButton } from 'storybook-root';6import { logInOutButton } from 'storybook-root';7import { logInOutButton } from 'storybook-root';8import { logInOutButton } from 'storybook-root';9import { logInOutButton } from 'storybook-root';10import { logInOutButton } from 'storybook-root';11import { logInOutButton } from 'storybook-root';12import { logInOutButton } from 'storybook-root';13import { logInOutButton } from 'storybook-root';14import { logInOutButton } from 'storybook-root';15import { logInOutButton } from 'storybook-root';16import { logInOutButton } from 'storybook-root';17import { logInOutButton } from 'storybook-root';18import { logInOutButton } from 'storybook-root';19import { logInOutButton } from 'storybook-root';20import { logInOutButton } from 'storybook-root';
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!