Advertisement
Guest User

Untitled

a guest
Dec 8th, 2016
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. (function() {
  2. const links = Array.from( document.querySelectorAll( 'link[title]' ) );
  3. const styles = Array.from( new Set( links.map( link => link.title ) ) );
  4. const select = document.createElement( 'select' );
  5.  
  6. if ( styles.length > 1 ) {
  7. select.setAttribute( 'style', 'position: absolute; top: 1em; right: 1em;' );
  8. for ( let i = 0; i < styles.length; i++ ) {
  9. const option = document.createElement( 'option' );
  10. option.text = 'CSS: ' + styles[ i ];
  11. option.value = styles[ i ];
  12. select.add( option );
  13. }
  14. document.body.appendChild( select );
  15.  
  16. select.addEventListener( 'change', function( event ) {
  17. const title = event.target.options[ event.target.selectedIndex ].value;
  18. links.forEach( function( link ){
  19. link.disabled = true;
  20. if ( link.title === title ) {
  21. link.disabled = false;
  22. }
  23. });
  24. });
  25. }
  26. }());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement