working on it ...

Filters

Explore Public Snippets

Sort by

Found 119k snippets

    public by electron modified Wednesday at 8:11:31 PM  63  0  2  0

    es6 async function

    template for async function es6 javascript js
    async function GetData() {
    	const resp = await axios.get('/url')
    	console.log(resp)
    }
    
    GetaData()

    public by szmerek modified Sep 6, 2017  217  2  5  0

    OnClick without setting an attribute of the link

    //<div id="dog" >Woow woow</div>
    
    
        (function() {
            document.getElementById("dog").onclick = function() { 
                alert('fuf fuf'); 
            };
        })();																								

    public by tttttttttt modified Aug 30, 2017  57  1  1  0

    ttttttttttttttttt

    tttt
    // ==UserScript==
    // @name         MicroScatter Cheater Script
    // @namespace    http://qsysmine.tk/
    // @version      0.1
    // @description  Press C on microscatter to win
    // @author       qsysmine
    // @match        https://quizlet.com/*/microscatter
    // @grant        none
    // ==/UserScript==
    
    (function() {
        var $ = window.jQuery;
        var cheat = function() {
            var ids = [];
            var checkhasid = function(id) {
                for(var i in ids) {
                    if(ids[i] == id) {
                        return true;
                    }
                }
                return false;
            };
            $('.cell').each(function(index){
    
                if(checkhasid($(this).attr("data-id"))) $('[data-id="' + $(this).attr("data-id") + '"]').trigger("click")
                if(!checkhasid($(this).attr("data-id"))) ids.push($(this).attr("data-id"));
    
            });
        };
        var z = 0;
        $('*').keyup(function(e) {
            if(e.keyCode == 67 && z == 0) {z = 1; cheat();}
        });
    })();
    
    

    public by tttttttttt modified Aug 30, 2017  56  0  1  0

    ttttttttttt

    ttttttttttttttt
    // ==UserScript==
    // @name         MicroScatter Cheater Script
    // @namespace    http://qsysmine.tk/
    // @version      0.1
    // @description  Press C on microscatter to win
    // @author       qsysmine
    // @match        https://quizlet.com/*/microscatter
    // @grant        none
    // ==/UserScript==
    
    (function() {
        var $ = window.jQuery;
        var cheat = function() {
            var ids = [];
            var checkhasid = function(id) {
                for(var i in ids) {
                    if(ids[i] == id) {
                        return true;
                    }
                }
                return false;
            };
            $('.cell').each(function(index){
    
                if(checkhasid($(this).attr("data-id"))) $('[data-id="' + $(this).attr("data-id") + '"]').trigger("click")
                if(!checkhasid($(this).attr("data-id"))) ids.push($(this).attr("data-id"));
    
            });
        };
        var z = 0;
        $('*').keyup(function(e) {
            if(e.keyCode == 67 && z === 0) {z = 1; cheat();}
        });
    })();
    
    

    public by szmerek modified Aug 20, 2017  105  0  3  0

    Remove part of a string before specified character

    //remove string before '&' if want to include character '&' then 'indexOf("&") + 0'
    var str = "black&white";
    str = str.substring(str.indexOf("&") + 1);
    
    //or use regex
    var str = "black&white";
    str = /&(.+)/.exec(str)[1];
    
    // or use .split() and .pop() 
    var str = "black&white";
    str = str.split("&").pop();						

    public by szmerek modified Aug 20, 2017  104  1  3  0

    Check whether a string matches a regex

    //RegExp allows to inject variable values into the regex string
    var str = "sample1";
    var re = new RegExp("^([a-z0-9]{5,})$");
    if (re.test(str)) {
        console.log("valid");
    } else {
        console.log("invalid");
    }					

    public by szmerek modified Aug 20, 2017  110  0  4  0

    Hide element(s) by class

    Some examples for hiding the class.
    //Ex 
    //<div class="appBanner">appbanner</div> 
    
    document.getElementsByClassName('appBanner')[0].style.visibility = 'hidden';
    
    //change the style rules of all elements matching the class
    
    [].forEach.call(document.querySelectorAll('.appBanner'), function (el) {
      el.style.visibility = 'hidden';
    });
    
    //If for...of is available then use
    
    for (let el of document.querySelectorAll('.appBanner')) el.style.visibility = 'hidden';
    
    //And the other one
    
    Array.filter( document.getElementsByClassName('appBanner'), function(elem){ elem.style.visibility = 'hidden'; });
    
    //and the last one
    
    var appBanners = document.getElementsByClassName('appBanner'), i;
    
    for (i = 0; i < appBanners.length; i += 1) {
        appBanners[i].style.display = 'none';
    }																								

    public by sunole modified Aug 5, 2017  82  0  1  0

    test javascript one

    // Enter here the actual content of the snippet.			
    var aaaa =5;

    public by ElectroSoft modified Jul 15, 2017  146  0  4  0

    Prueba de Ajax

    Prueba de Axaj en javascript nativo.
    function ajax()
    {
        var elements = document.getElementsByClassName("formVal");
        var formData = new FormData(); 
        for(var i=0; i<elements.length; i++)
        {
            formData.append(elements[i].name, elements[i].value);
        }
        var xmlHttp = new XMLHttpRequest();
            xmlHttp.onreadystatechange = function()
            {
                if(xmlHttp.readyState == 4 && xmlHttp.status == 200)
                {
                    alert(xmlHttp.responseText);
                }
            }
            xmlHttp.open("post", "prueba.php"); 
            xmlHttp.send(formData); 
    }

    public by rosskevin modified Jul 1, 2017  14  0  1  0

    material-ui NotificationCenter

    material-ui NotificationCenter: NotificationCenter.js
    // @flow
    
    import Queue from 'es-collections/Queue'
    import Snackbar from '@alienfast/material-ui/Snackbar'
    import PropTypes from 'prop-types'
    import React, {Component} from 'react'
    import Logger from './util/Logger'
    import Performance from './util/Performance'
    import Button from './Button'
    
    // if test, shorten duration for multiple messages - saves ~9 seconds on reset_password.feature
    const DefaultDuration = __TEST__ ? 750 : 3000
    
    type Props = {}
    
    type State = {
      queueSize: number,
      status: 'queueSizeChanged' | 'exited'
    }
    
    type Notification = {
      message: string,
      duration?: number,
      delay?: number,
      action?: string,
      onAction?: Function
    }
    
    const EmptyNotification = {
      message: ''
    }
    
    class NotificationCenter extends Component<void, Props, State> {
      static contextTypes = {
        eventBus: PropTypes.object.isRequired
      }
      props: Props
      state: State = {
        queueSize: 0,
        status: 'exited'
      }
      subscriptions: Array<EmitterSubscription>
      queue: Queue
      notification: ?Notification = EmptyNotification
    
      componentWillMount () {
        log.debug('componentWillMount')
        this.queue = new Queue()
        const { eventBus } = this.context
        // eventBus.registerEvent('NotificationCenter', 'notification')
        this.subscriptions = eventBus.subscribe('notification', this.handleNotification)
      }
    
      componentWillUnmount () {
        log.debug('componentWillUnmount')
        const { eventBus } = this.context
        eventBus.unsubscribe(this.subscriptions)
      }
    
      shouldComponentUpdate (nextProps: Props, nextState: State, nextContext: any) {
        //log.debug('shouldComponentUpdate', this.queue.size)
    
        // check to see if we are still showing the current notification
        const peek = this.queue.peek()
        //log.debug('compare notifications', this.notification === peek, this.notification, peek)
        if (this.notification === peek) {
          return false
        }
    
        return Performance.shouldComponentUpdate(this, nextProps, nextState, nextContext, true)
      }
    
      updateQueueSize () {
        this.setState({
          queueSize: this.queue.size,
          status: 'queueSizeChanged'
        })
      }
    
      handleNotification = (notification: Notification) => {
        const { delay } = notification
        const enqueue = () => {
          this.queue.enqueue(notification)
          log.debug('handleNotification', this.queue.size, notification)
          this.updateQueueSize()
        }
    
        if (delay) {
          setTimeout(enqueue, delay)
        } else {
          enqueue()
        }
      }
    
      handleRequestClose = (event: ?SyntheticUIEvent, reason: string, onAction?: Function) => {
        log.debug('handleRequestClose', reason, onAction, this.notification)
        const { duration } = (this.notification ? this.notification : {}) // wacky flow maybe type
        if (reason === 'clickaway' && !duration === 0) {  // allow clickaway on duration 0
          log.debug(reason)
        } else {
          if (onAction) {
            onAction()
          }
          this.queue.dequeue()
          this.updateQueueSize()
        }
      }
    
      handleExited = () => {
        log.debug('handleExited', this.notification)
        this.setState({ status: 'exited' })
      }
    
      render () {
        const { status } = this.state
        const size = this.queue.size
        let open
        let shownNotification: ?Notification
    
        if (size === 0) {
          // We must render the snackbar with an empty notification and close it so
          //  that we still achieve the ease out effect.
          shownNotification = this.notification
          this.notification = EmptyNotification
          open = false
        } else if (status === 'queueSizeChanged' && this.notification !== EmptyNotification) {
          // allow this message to exit
          shownNotification = this.notification
          open = false
        } else {
          // ready to display a new message from the queue
          shownNotification = this.notification = this.queue.peek()
          open = true
        }
    
        const { message, action: actionString, duration, onAction } = (shownNotification || {})
    
        // from the action string, create a button to trigger the action and dismiss the snackbar
        let action
        if (actionString) {
          action = [
            <Button
              key={actionString}
              color='accent'
              dense
              onClick={() => onAction ? onAction() : null}
            >
              {actionString}
            </Button>
          ]
        }
    
        const snackbarProps = {
          open,
          autoHideDuration: (duration === undefined ? DefaultDuration : duration)
        }
        log.debug('render Queue size:', size, ' status: ', status, message, snackbarProps)
    
        return (
          <Snackbar
            key={message}
            {...snackbarProps}
            action={action}
            onRequestClose={this.handleRequestClose}
            onExited={this.handleExited}
            SnackbarContentProps={{
              'aria-describedby': 'message-id'
            }}
            message={<span id='message-id'>{message}</span>}
          />
        )
      }
    }
    
    const log = Logger.get('NotificationCenter')
    
    log.debug('DefaultDuration', DefaultDuration, __TEST__)
    export default NotificationCenter
    
    
    
    • Public Snippets
    • Channels Snippets