snowden | Bonjour à tous,
Je viens demander un peu d'aide aux connaisseurs car je suis un peu (complètement) perdu.
Je précise tout de suite que je n'y connais rien en programmation !
Je suis en train de me créer une "startpage" perso en reprenant quelques scripts sur Github et en essayant à mon niveau (de mer..) de l'adapter à mon besoin.
Elle est presque finie mais j'ai un soucis et je n'arrive pas à intégrer la date du type "samedi 14 juillet 2018" dans mon script et que la date soit bien intégrée dans le même cadre que l'heure.
Sauriez-vous m'aider svp ? Merci par avance.
Voici l'unique page HTML du script, le reste ne sont que des images ou fonts.
Code :
- <!doctype html>
- <meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
- <meta http-equiv="x-dns-prefetch-control" content="on">
- <meta name="viewport" content="width=device-width, initial-scale=1">
- <link rel="icon" href="./favicon.ico" >
- <meta name="robots" content="noindex, nofollow">
- <title>Page d'accueil</title>
- <script>
- const CONFIG = {
- // the category, name, key, url, search path and color for your commands
- // if none of the specified keys are matched, the '*' key is used
- commands: [
- [null, 'DuckduckGO', 'd', 'https://duckduckgo.com', '/?q={}&t=h_&ia=news', '#373D53', './img/null/duckduckgo.png'],
- [null, 'Google', 'g', 'https://encrypted.google.com', '/search?q={}', '#373D53', './img/null/google.png'],
- [null, 'Qwant', '*', 'https://lite.qwant.com', '/?l=fr&q={}&t=web', '#373D53', './img/null/qwant.png'],
- [null, 'StartPage', 's', 'https://www.startpage.com', '/do/asearch?q={}&cat=web&nj=1&language=francais&lui=francais&t=air', '#A2C9EF', './img/null/startpage.png'],
- [null, 'Google Translate', 'translate', 'https://translate.google.fr', '/#en/fr/{}', '#4285f4', './img/null/translate.svg'],
-
- ['Divers', 'Pages Jaunes', 'pages jaunes', 'https://www.pagesjaunes.fr', '/annuaire/chercherlespros?quoiqui={}', '#FFEA03', './img/Divers/pages_jaunes.png'],
-
- ['Forums', 'Forum JVC', 'forum jvc', 'http://www.jeuxvideo.com/forums.htm', '/forums/recherche.php?q={}', '#004565', './img/Forums/jvc.png'],
- ['Forums', 'Forum HFR', 'hfr', 'https://forum.hardware.fr', '/forum1.php?config=hfr.inc&cat=1&post_cat_list=|1*hfr|16*hfr|25*hfr|3*hfr|4*hfr|22*hfr|21*hfr|11*hfr|10*hfr|6*hfr|13*hfr|&trash=0&orderSearch=1&recherches=1&resSearch=20&jour=7&mois=4&annee=2018&titre=1&search={}&pseud=&daterange=2&searchtype=1&searchall=1', '#394F67', './img/Forums/hfr.png'],
- ['Forums', 'Forum Next Inpact', 'forum next inpact', 'https://forum.nextinpact.com', '/search/?q={}', '#3F6593', './img/Forums/next_inpact.png'],
- ['Forums', 'Reddit', 'reddit', 'https://www.reddit.com', '/search?q={}', '#5f99cf', './img/Forums/reddit.svg'],
- ['Informatique', 'Discord', 'discord', 'https://discordapp.com', null, '#1E1F22', './img/Informatique/discord.svg'],
- ['Informatique', 'Dropbox', 'dropbox', 'https://www.dropbox.com/fr/', null, '#333333', './img/Informatique/dropbox.svg'],
- ['Informatique', 'DL Compare', 'dl compare', 'https://www.dlcompare.fr', '/search?q={}', '#363636', './img/Informatique/dl_compare.png'],
- ['Informatique', 'Imgur', 'imgur', 'https://imgur.com/upload', null, '#474A50', './img/Informatique/imgur.png'],
- ['Informatique', 'Jeuxvideo.com', 'jvc', 'http://www.jeuxvideo.com/', '/recherche.php?q={}', '#DFDFDF', './img/Informatique/jvc.png'],
- ['Informatique', 'MacG', 'macg', 'https://www.macg.co/', '/recherche/{}&o=date', '#FF6602', './img/Informatique/macg.png'],
- ['Informatique', 'Next Inpact', 'next inpact', 'https://www.nextinpact.com', '/recherche?_search={}&RubriqueId=&Author=&OrderType=date&DateStartPeriod=&DateEndPeriod=&ListTypeContent.actus_view=true&ListTypeContent.dossiers_view=true&ListTypeContent.bonsplans_view=true&ListTypeContent.archives_view=true', '#06455A', './img/Informatique/next_inpact.png'],
- ['Informatique', 'Virus Total', 'virus total', 'https://www.virustotal.com/fr', null, '#292929', './img/Informatique/virus_total.svg'],
- ['Informatique', 'XDA Developers', 'xda', 'https://forum.xda-developers.com/', '/sitesearch.php?q={}', '#323232', './img/Informatique/xda.svg'],
-
- ['Multimedia', 'Écouter radio en ligne', 'radio', 'http://www.ecouterradioenligne.com', '/#{}', '#00323D', './img/Multimedia/radio.png'],
- ['Multimedia', 'France Bleu', 'France bleu', 'https://www.francebleu.fr', null, '#0077D6', './img/Multimedia/France_bleu.svg'],
- ['Multimedia', 'Dailymotion', 'dailymotion', 'https://www.dailymotion.com/fr', '/search/{}', '#07A7E0', './img/Multimedia/dailymotion.svg'],
- ['Multimedia', 'Netflix', 'netflix', 'https://www.netflix.com/browse', '/search?q={}', '#1B1B1B', './img/Multimedia/netflix.svg'],
- ['Multimedia', 'Play Music', 'google music', 'https://play.google.com/music/listen#/all', '/music/listen#/sr/{}', '#282828', './img/Multimedia/google_play_music.svg'],
- ['Multimedia', 'Prime Vidéo', 'prime video', 'https://www.primevideo.com', '/search/ref=atv_nb_sr?phrase={}&ie=UTF8', '#282828', './img/Multimedia/amazon_prime_video.svg'],
- ['Multimedia', 'SoundCloud', 'soundcloud', 'https://soundcloud.com/discover', '/search?q={}', '#363636', './img/Multimedia/soundcloud.svg'],
- ['Multimedia', 'Spotify', 'spotify', 'https://open.spotify.com/browse/featured', '/search/results/{}', '#613031', './img/Multimedia/spotify.svg'],
- ['Multimedia', 'The movie database', 'tmdb', 'https://www.themoviedb.org', '/search/movie?query={}', '#112229', './img/Multimedia/tmdb.svg'],
- ['Multimedia', 'TVDB', 'tvdb', 'https://www.thetvdb.com', '/search?q={}&l=fr', '#2C2C2C', './img/Multimedia/tvdb.png'],
- ['Multimedia', 'Twitch', 'twitch', 'https://www.twitch.tv/directory', null, '#302A43', './img/Multimedia/twitch.svg'],
- ['Multimedia', 'Youtube Music', 'yt music', 'https://music.youtube.com', '/search?q={}', '#1A1A1A', './img/Multimedia/youtube_music.svg'],
- ['Sport', 'Eurosport', 'eurosport', 'https://www.eurosport.fr', null, '#191E48', './img/Sport/eurosport.svg'],
- ['Sport', 'L’équipe', 'lequipe', 'https://www.lequipe.fr', '/recherche/search.php?r={}&jd=&md=&ad=&jf=&mf=&af=&t=ALL&s1=efr&adv=0&o=D&s=ALL', '#F8F8F8', './img/Sport/equipe.svg'],
- ['Sport', 'Sports.fr', 'sports', 'http://www.sports.fr', null, '#005090', './img/Sport/sports.svg'],
- ],
- // instantly redirect when a key is matched
- // put a space before any other queries to prevent unwanted redirects
- instantRedirect: false,
- // open queries in a new tab
- newTab: false,
- // dynamic background colors when command domains are matched
- colors: true,
- // specify a theme file
- // remove or set to false to use the hardcoded theme
- theme: false,
- // the delimiter between the key and your search query
- // e.g. to search GitHub for potatoes you'd type "g:potatoes"
- searchDelimiter: ':',
- // the delimiter between the key and a path
- // e.g. type "r/r/unixporn" to go to "reddit.com/r/unixporn"
- // pathDelimiter: '/',
- // the delimiter between the hours and minutes in the clock
- clockDelimiter: ':',
- // note: you can pass in your search query via the q query param
- // e.g. going to file:///path/to/tilde/index.html?q=hamsters is equivalent
- // to typing "hamsters" and pressing enter
- };
- </script>
- <style type="text/css">
- @font-face {font-family:"2018"; src:url("./font/2018.ttf" );}
- @font-face {font-family:"digital"; src:url("./font/digital.ttf" );}
- :root {
- --color0: #202020;
- --color15: #ffffff;
- --color20: #00a5ff;
- }
- body {
- position: absolute;
- top: -21%;
- left: 0;
- width: 100%;
- height: 100%;
- margin: 0;
- padding: 0;
- transition: background .2s;
- background-color: var(--color0);
- font-family:"2018";
- color: var(--color15);
- background: url(./img/background.jpg);
- background-position: no-repeat center 0;
- background-size: cover;
- }
- input,
- button,
- input:focus,
- button:focus {
- display: block;
- box-sizing: border-box;
- width: 100%;
- margin: 0;
- border: 0;
- outline: 0;
- background: transparent;
- color: #fff;
- font-family:"2018";
- text-align: center;
- -webkit-appearance: none;
- -moz-appearance: none;
- }
- ul,
- li {
- margin: 0;
- padding: 0;
- list-style: none;
- }
- a,
- a:focus {
- color: #DAF7A6;
- outline: 0;
- }
- #clock {
- -webkit-text-fill-color: white;
- color: whitesmoke;
- border-radius: 5px;
- -moz-box-shadow: 0 20px 30px rgba(0, 0, 0, 0.6);
- -webkit-box-shadow: 0 20px 30px rgba(0, 0, 0, 0.6);
- /* box-shadow: 0 20px 30px rgba(0, 0, 0, 0.6); */
- /* box-shadow: -1px 4px 5px 4px rgba(0, 0, 0, 0.7); */
- box-shadow: 3px 3px 10px 3px #000;
- border: 1px solid rgba(255, 255, 255, 0.3);
- padding: 0px 20px 0px 20px;
- -moz-box-sizing: border-box;
- -webkit-box-sizing: border-box;
- box-sizing: border-box;
- text-shadow: 0 5px 1px rgba(0, 0, 0, 0.4);
- transition: box-shadow .3s ease;
- background-color: rgba(0.12, 0.12, 0.12, 0.12);
- cursor: default;
- font-size: 8rem;
- font-family:"digital";
- text-align: center;
- }
- #search-form {
- background: url(./img/background.jpg);
- background-position: no-repeat center 0;
- background-size: cover;
- color: #ffffff;
- z-index: 2;
- }
- #search-form>div {
- -webkit-text-fill-color: white;
- color: whitesmoke;
- top: 35%;
- border-radius: 5px;
- -moz-box-shadow: 0 20px 30px rgba(0, 0, 0, 0.6);
- -webkit-box-shadow: 0 20px 30px rgba(0, 0, 0, 0.6);
- box-shadow: 0 20px 30px rgba(0, 0, 0, 0.6);
- border: 1px solid rgba(255, 255, 255, 0.3);
- padding: 10px;
- font-size: 0.7rem;
- text-align: center;
- -moz-box-sizing: border-box;
- -webkit-box-sizing: border-box;
- box-sizing: border-box;
- text-shadow: 0 5px 1px rgba(0, 0, 0, 0.4);
- transition: box-shadow .3s ease;
- background-color: rgba(0.12, 0.12, 0.12, 0.12);
- }
- #search-input,
- #search-input:focus {
- width: 100%;
- font-size: 10px;
- font-weight: lighter;
- text-transform: none;
- /* font-family:"2018"; */
- }
- #help {
- background: url(./img/background.jpg);
- background-position: no-repeat center 0;
- background-size: cover;
- display: block;
- padding: 8vw;
- background-color: var(--color0);
- font-size: 1.3rem;
- z-index: 1;
- }
- .category {
- text-align: center;
- font-size: 19px;
- letter-spacing: 1px;
- }
- .category:last-of-type {
- text-align: center;
- font-size: 19px;
- letter-spacing: 1px;
- }
- .category-name {
- -webkit-text-fill-color: white;
- color: whitesmoke;
- border-radius: 5px;
- -moz-box-shadow: 0 20px 30px rgba(0, 0, 0, 0.6);
- -webkit-box-shadow: 0 20px 30px rgba(0, 0, 0, 0.6);
- box-shadow: 0 20px 30px rgba(0, 0, 0, 0.6);
- border: 1px solid rgba(255, 255, 255, 0.3);
- padding: 0px 40px 0px 40px;
- -moz-box-sizing: border-box;
- -webkit-box-sizing: border-box;
- box-sizing: border-box;
- text-shadow: 0 5px 1px rgba(0, 0, 0, 0.4);
- transition: box-shadow .3s ease;
- background-color: rgba(92, 92, 92, 0.42);
- cursor: default;
- font-family:"2018";
- text-align: center;
- }
- .command a {
- display: block;
- position: relative;
- margin: 1em 0;
- font-size: .8em;
- line-height: 1em;
- text-decoration: none;
- }
- .command:last-of-type a {
- margin-bottom: 0;
- }
- .command-name {
- position: relative;
- overflow: hidden;
- }
- .command-name::after {
- content: ' ';
- position: absolute;
- right: 0;
- bottom: -.35em;
- left: 0;
- height: 2px;
- transition: .2s;
- transform: translateX(-2em);
- background: var(--color15);
- opacity: 0;
- }
- .command a:hover .command-name::after,
- .command a:focus .command-name::after {
- transform: translateX(0);
- opacity: 1;
- }
- .overlay {
- position: fixed;
- top: 0%;
- left: 0;
- overflow: auto;
- box-sizing: border-box;
- width: 100%;
- height: 100%;
- visibility: hidden;
- }
- body.help #help.overlay,
- body.form #search-form.overlay {
- visibility: visible;
- }
- .center {
- display: flex;
- justify-content: center;
- align-items: center;
- width: 100%;
- height: 100%;
- box-sizing: border-box;
- }
- @media (min-width: 500px) {
- .categories {
- display: grid;
- grid-template-columns: 250px 185px;
- justify-content: space-around;
- }
- .category:nth-last-child(2) {
- margin-bottom: 0;
- }
- #search-input,
- #search-input:focus {
- font-size: 3em;
- }
- }
- @media (min-width: 1000px) {
- #help {
- display: flex;
- padding: 0;
- }
- .category {
- margin: 2rem 0;
- }
- .categories {
- grid-template-columns: repeat(2, 300px) 185px;
- }
- }
- @media (min-width: 1700px) {
- .categories {
- grid-template-columns: repeat(5, 250px) 185px;
- }
- }
-
- </style>
- <div class="center">
- <time id="clock"></time>
- </div>
- <form class="overlay center" id="search-form" autocomplete="off" spellcheck="false">
- <img id="search-logo" src="./img/interrogation.png" style="position: fixed;padding-bottom: 400px;" height="188">
- <div>
- <input id="search-input" type="text">
- </div>
- </form>
- <aside class="overlay center" id="help"></aside>
-
- <script>
- const $ = {
- bodyClassAdd: c => $.el('body').classList.add(c),
- bodyClassHas: c => $.el('body').classList.contains(c),
- bodyClassRemove: c => $.el('body').classList.remove(c),
- el: s => document.querySelector(s),
- els: s => [].slice.call(document.querySelectorAll(s) || []),
- escapeRegex: s => s.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'),
- ieq: (a, b) => a.toLowerCase() === b.toLowerCase(),
- iin: (a, b) => a.toLowerCase().indexOf(b.toLowerCase()) !== -1,
- isDown: e => ['c-n', 'down', 'tab'].includes($.key(e)),
- isRemove: e => ['backspace', 'delete'].includes($.key(e)),
- isUp: e => ['c-p', 'up', 's-tab'].includes($.key(e)),
- jsonp: url => {
- let script = document.createElement('script');
- script.src = url;
- $.el('head').appendChild(script);
- },
- key: e => {
- const ctrl = e.ctrlKey;
- const shift = e.shiftKey;
- switch (e.which) {
- case 8: return 'backspace';
- case 9: return shift ? 's-tab' : 'tab';
- case 13: return 'enter';
- case 16: return 'shift';
- case 17: return 'ctrl';
- case 18: return 'alt';
- case 27: return 'escape';
- case 38: return 'up';
- case 40: return 'down';
- case 46: return 'delete';
- case 78: return ctrl ? 'c-n' : 'n';
- case 80: return ctrl ? 'c-p' : 'n';
- case 91: return 'super';
- }
- },
- };
- class Clock {
- constructor(options) {
- this._el = $.el('#clock');
- this._delimiter = options.delimiter;
- this._form = options.form;
- this._setTime = this._setTime.bind(this);
- this._registerEvents();
- this._start();
- }
- _pad(num) {
- return ('0' + num.toString()).slice(-2);
- }
- _registerEvents() {
- this._el.addEventListener('click', this._form.show);
- }
- _setTime() {
- const date = new Date();
- const hours = this._pad(date.getHours());
- const minutes = this._pad(date.getMinutes());
- this._el.innerHTML = hours + this._delimiter + minutes;
- }
- _start() {
- this._setTime();
- setInterval(this._setTime, 1000);
- }
- }
- class Help {
- constructor(options) {
- this._el = $.el('#help');
- this._commands = options.commands;
- this._newTab = options.newTab;
- this._toggled = false;
- this._buildAndAppendLists();
- this._bindMethods();
- this._registerEvents();
- }
- toggle(show) {
- this._toggled = (typeof show !== 'undefined') ? show : !this._toggled;
- this._toggled ? $.bodyClassAdd('help') : $.bodyClassRemove('help');
- }
- _bindMethods() {
- this._handleKeydown = this._handleKeydown.bind(this);
- }
- _buildAndAppendLists() {
- const lists = document.createElement('ul');
- lists.classList.add('categories');
- this._getCategories().forEach(category => {
- lists.insertAdjacentHTML(
- 'beforeend',
- `<li class="category">
- <h2 class="category-name">${category}</h2>
- <ul>${this._buildListCommands(category)}</ul>
- </li>`
- );
- });
- this._el.appendChild(lists);
- }
- _buildListCommands(category) {
- return this._commands.map(([cmdCategory, name, key, url]) => {
- if (cmdCategory === category) {
- return (
- `<li class="command">
- <a href="${url}" target="${this._newTab ? '_blank' : '_self'}">
- <!--<span class="command-key">${key}</span>-->
- <span class="command-name">${name}</span>
- </a>
- </li>`
- );
- }
- }).join('');
- }
- _getCategories() {
- const categories = this._commands
- .map(([category]) => category)
- .filter(category => category);
- return [...new Set(categories)];
- }
- _handleKeydown(e) {
- if ($.key(e) === 'escape') this.toggle(false);
- }
- _registerEvents() {
- document.addEventListener('keydown', this._handleKeydown);
- }
- }
- class Influencer {
- constructor(options) {
- this._limit = options.limit;
- this._queryParser = options.queryParser;
- }
- addItem() {}
- getSuggestions() {}
- _addSearchPrefix(items, query) {
- const searchPrefix = this._getSearchPrefix(query)
- return items.map(s => searchPrefix ? searchPrefix + s : s);
- }
- _getSearchPrefix(query) {
- const { isSearch, key, split } = this._parseQuery(query);
- return isSearch ? `${key}${split} ` : false;
- }
- _parseQuery(query) {
- return this._queryParser.parse(query);
- }
- }
- class DuckDuckGoInfluencer extends Influencer {
- constructor({ queryParser }) {
- super(...arguments);
- }
- getSuggestions(rawQuery) {
- const { query } = this._parseQuery(rawQuery);
- if (!query) return Promise.resolve([]);
- return new Promise(resolve => {
- const endpoint = 'https://duckduckgo.com/ac/';
- const callback = 'autocompleteCallback';
- window[callback] = res => {
- const suggestions = res.map(i => i.phrase)
- .filter(s => !$.ieq(s, query))
- .slice(0, this._limit)
- resolve(this._addSearchPrefix(suggestions, rawQuery));
- };
- $.jsonp(`${endpoint}?callback=${callback}&q=${query}`);
- });
- }
- }
- class Suggester {
- constructor(options) {
- this._limit = options.limit;
- this._suggestionEls = [];
- this._bindMethods();
- this._registerEvents();
- }
- setOnClick(callback) {
- this._onClick = callback;
- }
- setOnHighlight(callback) {
- this._onHighlight = callback;
- }
- setOnUnhighlight(callback) {
- this._onUnhighlight = callback;
- }
- _unHighlight(e) {
- const el = $.el('.highlight');
- if (el) {
- this._onUnhighlight();
- el.classList.remove('highlight');
- if (e) e.preventDefault();
- }
- }
- }
- class QueryParser {
- constructor(options) {
- this._commands = options.commands;
- this._searchDelimiter = options.searchDelimiter;
- this._pathDelimiter = options.pathDelimiter;
- this._protocolRegex = /^[a-zA-Z]+:\/\//i;
- this._urlRegex = /^((https?:\/\/)?[\w-]+(\.[\w-]+)+\.?(:\d+)?(\/\S*)?)$/i;
- }
- parse(query) {
- const res = { query: query, split: null };
- if (query.match(this._urlRegex)) {
- const hasProtocol = query.match(this._protocolRegex);
- res.redirect = hasProtocol ? query : 'http://' + query;
- } else {
- const splitSearch = query.split(this._searchDelimiter);
- const splitPath = query.split(this._pathDelimiter);
- this._commands.some(([category, name, key, url, searchPath]) => {
- res.isKey = query === key;
- res.isSearch = !res.isKey && splitSearch[0] === key;
- res.isPath = !res.isKey && splitPath[0] === key;
- if (res.isKey || res.isSearch || res.isPath) {
- res.key = key;
- if (res.isSearch && searchPath) {
- res.split = this._searchDelimiter;
- res.query = this._shiftAndTrim(splitSearch, res.split);
- res.redirect = this._prepSearch(url, searchPath, res.query);
- } else if (res.isPath) {
- res.split = this._pathDelimiter;
- res.path = this._shiftAndTrim(splitPath, res.split);
- res.redirect = this._prepPath(url, res.path);
- } else {
- res.redirect = url;
- }
- return true;
- }
- if (key === '*') {
- res.redirect = this._prepSearch(url, searchPath, query);
- }
- });
- }
- res.color = this._getColorFromUrl(res.redirect);
- res.logo = this._getLogoFromUrl(res.redirect);
- return res;
- }
- _getColorFromUrl(url) {
- const domain = this._getHostname(url);
- const color = this._commands
- .filter(c => this._getHostname(c[3]) === domain)
- .map(c => c[5])[0];
- return color || null;
- }
- _getLogoFromUrl(url) {
- const domain = this._getHostname(url);
- const logo = this._commands
- .filter(c => this._getHostname(c[3]) === domain)
- .map(c => c[6])[0];
- return logo || null;
- }
- _getHostname(url) {
- const parser = document.createElement('a');
- parser.href = url;
- return parser.hostname.replace(/^www./, '');
- }
- _prepPath(url, path) {
- return this._stripUrlPath(url) + '/' + path;
- }
- _prepSearch(url, searchPath, query) {
- if (!searchPath) return url;
- const baseUrl = this._stripUrlPath(url);
- const urlQuery = encodeURIComponent(query);
- searchPath = searchPath.replace('{}', urlQuery);
- return baseUrl + searchPath;
- }
- _shiftAndTrim(arr, delimiter) {
- arr.shift();
- return arr.join(delimiter).trim();
- }
- _stripUrlPath(url) {
- const parser = document.createElement('a');
- parser.href = url;
- return `${parser.protocol}//${parser.hostname}`;
- }
- }
- class Form {
- constructor(options) {
- this._formEl = $.el('#search-form');
- this._inputEl = $.el('#search-input');
- this._logoEl = $.el('#search-logo');
- this._colors = options.colors;
- this._help = options.help;
- this._queryParser = options.queryParser;
- this._instantRedirect = options.instantRedirect;
- this._newTab = options.newTab;
- this._inputElVal = '';
- this._bindMethods();
- this._registerEvents();
- this._loadQueryParam();
- }
- hide() {
- $.bodyClassRemove('form'),
- this._inputEl.value = '';
- this._inputElVal = '';
- }
- show() {
- $.bodyClassAdd('form');
- this._inputEl.focus();
- }
- _bindMethods() {
- this.hide = this.hide.bind(this);
- this.show = this.show.bind(this);
- this._clearPreview = this._clearPreview.bind(this);
- this._handleKeydown = this._handleKeydown.bind(this);
- this._handleInput = this._handleInput.bind(this);
- this._previewValue = this._previewValue.bind(this);
- this._submitForm = this._submitForm.bind(this);
- this._submitWithValue = this._submitWithValue.bind(this);
- }
- _clearPreview() {
- this._previewValue(this._inputElVal);
- this._inputEl.focus();
- }
- _handleKeydown(e) {
- if ($.isUp(e) || $.isDown(e) || $.isRemove(e)) return;
- switch ($.key(e)) {
- case 'alt':
- case 'ctrl':
- case 'enter':
- case 'shift':
- case 'super': return;
- case 'escape': this.hide(); return;
- }
- this.show();
- }
- _handleInput() {
- const newQuery = this._inputEl.value;
- const isHelp = newQuery === '?';
- const { isKey } = this._queryParser.parse(newQuery);
- this._inputElVal = newQuery;
- this._setBackgroundFromQuery(newQuery);
- if (!newQuery || isHelp) this.hide();
- if (isHelp) this._help.toggle();
- if (this._instantRedirect && isKey) this._submitWithValue(newQuery);
- }
- _loadQueryParam() {
- const q = new URLSearchParams(window.location.search).get('q');
- if (q) this._submitWithValue(q);
- }
- _previewValue(value) {
- this._inputEl.value = value;
- this._setBackgroundFromQuery(value);
- }
- _redirect(redirect) {
- if (this._newTab) window.open(redirect, '_blank');
- else window.location.href = redirect;
- }
- _registerEvents() {
- document.addEventListener('keydown', this._handleKeydown);
- this._inputEl.addEventListener('input', this._handleInput);
- this._formEl.addEventListener('submit', this._submitForm, false);
- }
- _setBackgroundFromQuery(query) {
- if (!this._colors) return;
- const { color, logo } = this._queryParser.parse(query);
- this._formEl.style.backgroundColor = color;
- if (logo) {
- this._logoEl.src = logo;
- // show
- this._logoEl.style.display = 'block';
- } else {
- // hide
- this._logoEl.style.display = 'none';
- }
- }
- _submitForm(e) {
- if (e) e.preventDefault();
- const query = this._inputEl.value;
- if (this._suggester) this._suggester.success(query);
- this.hide();
- this._redirect(this._queryParser.parse(query).redirect);
- }
- _submitWithValue(value) {
- this._inputEl.value = value;
- this._submitForm();
- }
- }
- </script>
- <script>
- const getHelp = () => {
- return new Help({
- commands: CONFIG.commands,
- newTab: CONFIG.newTab,
- });
- };
- const getQueryParser = () => {
- return new QueryParser({
- commands: CONFIG.commands,
- pathDelimiter: CONFIG.pathDelimiter,
- searchDelimiter: CONFIG.searchDelimiter,
- });
- };
- const getForm = () => {
- return new Form({
- colors: CONFIG.colors,
- help: getHelp(),
- instantRedirect: CONFIG.instantRedirect,
- newTab: CONFIG.newTab,
- queryParser: getQueryParser(),
- suggester: CONFIG.suggestions ? getSuggester() : false,
- });
- };
- new Clock({
- delimiter: CONFIG.clockDelimiter,
- form: getForm(),
- });
- if (CONFIG.theme) {
- const link = document.createElement('link');
- link.href = CONFIG.theme;
- link.type = 'text/css';
- link.rel = 'stylesheet';
- $.el('head').appendChild(link);
- }
- </script>
|
---------------
« A l’origine de toute erreur attribuée à l’ordinateur, vous trouverez au moins deux erreurs humaines. Dont celle consistant à attribuer l’erreur à l’ordinateur. »
|