Skip to content

Instantly share code, notes, and snippets.

@kgashok
Last active November 27, 2018 05:24
Show Gist options
  • Save kgashok/ecca74b0255db24530deee07fd880a84 to your computer and use it in GitHub Desktop.
Save kgashok/ecca74b0255db24530deee07fd880a84 to your computer and use it in GitHub Desktop.
bookmarkletCreation.md

Bookmarklet for Custom Starting Points

  1. Create a duplicate bookmark by copy-pasteing an existing bookmark on your bookmark bar. The newly created bookmark will serve as a placeholder for putting in some bookmarklet JavaScript code.
    • Edit the bookmark and change the Name to CustomCD or whatever you might prefer to call it. You may choose to skip this step and edit the name when you update the URL in step 4 below.
  2. Select the below Javascript code by starting your cursor from before the javacript keyword all the way to the () at the very end. Copy the selection into your Clipboard by using Ctrl-C.
  3. Right-click on the CustomCD bookmark from Step 2 and choose "Edit".
  4. Paste the JS code (use Ctrl-V) directly into the dialog box referred to as "URL"
  5. If you haven't change the "Name" of the bookmark, edit that before you Save the bookmark.

That's it! You have now a bookmarklet which will extract the hexadecimal ID, the avatar and the traffic light (you can override the default total count) from any valid CD session that you might have created.

  1. Select the tab wherein you have the CD session from which you want to create a custom session.
  2. Click on the newly created bookmarklet and respond to the prompts appropriately.
  3. Finally, click "Yes" to the "Do you want to launch?" and it will fork a new CD session.
  4. Enjoy!

Javascript Code for bookmarklet

javascript:javascript:(function()%7Bvar%20url%20%3D%20window.location.href%3Balert(url)%3Bconst%20regex%20%3D%20%2F.%5C%2F(%5B0-9%2CA-Z%5D%7B10%7D)%3F.%3D(%5Ba-z%5D*)%2Fgi%3Bconst%20str%20%3D%20url%3Bvar%20response%3Bvar%20m%20%3D%20regex.exec(str)%3Bif%20(m!%3D%3D%20null)%20%7Bvar%20hexid%20%3D%20m%5B1%5D%3Bvar%20avatar%20%3D%20m%5B2%5D%3Bvar%20count%20%3D%20document.querySelector(%22.traffic-lights-count%22)%3Bif%20(count.textContent.length%20%3D%3D%200)%20%7Balert(%22No%20traffic%20lights!%20Cannot%20fork!%22)%3B%7Delse%20%7Bvar%20light%20%3D%20prompt(%22Please%20enter%20the%20traffic%20light%20number%22%2C%20count.textContent)%3Bif%20(light%20%3D%3D%20null)%20light%20%3D%20-1%3Bvar%20cdlink%20%3D%20window.location.host%3Bcdlink%20%3D%20%22http%3A%2F%2F%22%20%2B%20cdlink%20%2B%20%22%2Fforker%2Ffork%2F%22%3Bcdlink%20%3D%20cdlink%20%2B%20hexid%3Bcdlink%20%3D%20cdlink%20%2B%20%22%3Favatar%3D%22%20%2B%20avatar%3Bcdlink%20%3D%20cdlink%20%2B%20%22%26tag%3D%22%20%2B%20light%3Balert(cdlink)%3Bresponse%20%3D%20confirm(%22Do%20you%20want%20to%20launch%5Cn%22%20%2B%20cdlink%20%2B%20%22%3F%22)%3Bif%20(response%20%3D%3D%3D%20true)%7Bwindow.open(cdlink%2C%20'_blank')%3Bwindow.focus()%3B%7D%7D%7Delse%20%7Bresponse%20%3D%20confirm(%22Not%20a%20valid%20CD%20session!%5CnDo%20you%20want%20to%20try%20Python%2FPytest%20on%20CyberDojo%3F%22)%3Bif%20(response%20%3D%3D%3D%20true)%20%7Bwindow.open(%22http%3A%2F%2Fj.mp%2FcdPython%22%2C%20'_blank')%3Bwindow.focus()%3B%7D%7D%7D)()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment