Help us understand the problem. What is going on with this article?

ユーザーページにLGTMトップの記事を表示するユーザースクリプト

Screen Shot 2020-03-26 at 08.32.09-fullpage.png

// ==UserScript==
// @name         Qiita top items
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  なんか名前が変わったやつをたくさんあつめたのを表示する
// @author       khsk
// @match        https://qiita.com/*
// @exclude      https://qiita.com/
// @exclude      https://qiita.com/timeline*
// @exclude      https://qiita.com/tag-feed*
// @exclude      https://qiita.com/notifications*
// @grant        none
// ==/UserScript==

(async function() {
  'use strict';
  // APIで取得しようと思ったけどソートしないといけないし100投稿ごとにタイムラグが大きくなるのでもう検索結果を雑に流し込むことにした

  //ユーザーページ判定とid取得を雑に新ページ対応
  const userMain = document.querySelector('[class^="UserMain"]')
  if (!userMain) {
    return
  }

  // ページが変わったからまたID取得が怪しいかも @削除
  const id = document.querySelector('[class^="AccountBaseInfo__UrlName"]').textContent.substr(1)

  const response = await fetch('https://qiita.com/search?&sort=like&q=user%3A' + id)
  if (response.ok == false || response.status != 200) {
    console.error('fetch error', id , response)
    return
  }

  const dummyDOM = document.createElement('div')
  dummyDOM.innerHTML = await response.text()
  // ちょっとnth-of-typeの挙動を意図通りにできない。クラスでなくtag名(div)にかかるのでresult以外のdivひとつ分増やしている
  const topItems = dummyDOM.querySelectorAll('.searchResultContainer_main > div.searchResult:nth-of-type(-n+6)')
  const sideBar = document.querySelector('[class^="UserSidebar"]')

  topItems.forEach ((topItem)=> {
    // アイコン画像がでっかく表示されちゃうから雑に消す
    let tmp = topItem.querySelector('.searchResult_left')
    tmp.parentElement.removeChild(tmp)
    // 概要も不要
    tmp = topItem.querySelector('.searchResult_snippet')
    tmp.parentElement.removeChild(tmp)
    sideBar.innerHTML += topItem.outerHTML
    // TODO(しない)整形もっとがんばる
  })
})();

デザイン思い出せない

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした